Jump to content

Help understand the _ files in the template


mikeroosa
 Share

Recommended Posts

I just installed ProcessWire for the first time and I've perused the documentation but haven't seen an explanation of the template files that start with an _. Can someone explain to me how those work?

Also, how come they have an opening php tag but no closing tag? 

Is there anything that explains this in depth?

Link to comment
Share on other sites

Hi mikeroosa and welcome to PW.

Both of those are optional.

The leading underscore is simply a convention so you know those files are not actual template files, but rather php includes (files that get included into other files). This is also common outside of PW.

The omission of the closing tag has several benefits. A quick google will help to explain why:

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php+omit+closing+tag

  • Like 6
Link to comment
Share on other sites

Thank you Adrian. That clears things up. I'm not really a php programmer but want to learn it well enough to set up a template. I'm a .net dev and the idea of omitting a closing tag seemed odd to me. 

How does ProcessWire know to include the _ files. Is it defined somewhere in the admin?

Link to comment
Share on other sites

They are either included in template files with the php include statement or autoincluded in site config file. You can read this wonderful tutorial to get all the nuts and bolts quick.

They also can be included in the admin in the FIles tab of the template edit page.

Edited by Ivan Gretsky
  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

I would like to see some examples of people using the _ files for non direct theming, as I've not really done it that way yet. I also find it really annoying that those files are set be default in the config.

Link to comment
Share on other sites

do you know this thread? https://processwire.com/talk/topic/740-a-different-way-of-using-templates-delegate-approach/ a lot to read ;)

i really like the structure with _func.php, _init.php and _main.php - very clear, very flexible. i'm doing it like this most of the time:

https://processwire.com/talk/topic/740-a-different-way-of-using-templates-delegate-approach/?p=75853

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...