Jump to content

Recommended Posts

Posted

I've abstracted all of my templating to the point that the files at /site/templates/[template_name].php are completely empty. Is there any way to get rid of the need for the empty template file and still have processwire's built-in routing work as expected?

Thanks!

Jason

Posted

What do you mean by build in routing? PW is routing traffic to the corresponding template files, which you could change to the same one for each template in the settings. I'm just not sure what exactly you want to preserve.

Posted

Let's say I have a "template" called "bio."

In the most basic processwire usage, there's a 1-1 relationship between templates and template files. If you want to view a page created using the "bio" template at its natural URL, you have to have a corresponding file at /site/templates/bio.php.

If you create a "no-file" template for bios, in order to display a bio page, you have to include it from another template, use url segments, etc. -- in short, do the routing yourself.

I want to use the normal routing mechanism (as if there were a bio.php file), but not have to physically create bio.php, because at this point it's just an empty placeholder.

Posted

I guess you could set a common (empty) file as template file using a hook but maybe I'm wrong. Otoh there are so many files in the system you will never use, why bother with these?

Posted

@Jason

I'm still not sure how you would keep the routing, but not have files. Either you've multiple files that get only called by their template's pages or you have a single file, that does get called for each of those request, where you'd need to differentiate the calls by yourself.

Posted

For my purposes, it's close enough to be able to specify a different template file for each template. I point them all to main.php, which is empty. In config.php, I'm prepending an init.inc file that loads the correct view based on the value of $page->template.

That may sound a bit circuitous, but it lets me have a structure like this (personal preference):

/site/templates/

    init.inc (all bootstrap code, prepended via config.php)

    main.php (empty)

    views/

        base/

            base.inc (global layout/markup, header, footer, nav, etc.)

            base.js

            base.less

        bio/

            bio.inc

            bio.js

            bio.less

        location/

        ...etc. for each view

I'll probably stop prepending init.inc, and just move that code into main.php, since I still have to have one template file in the usual location anyway.

Posted

I haven't read this thoroughly, so likely missing the point, but what about using the alternate template filename option from the Files tab for each template?

Posted

I haven't read this thoroughly, so likely missing the point, but what about using the alternate template filename option from the Files tab for each template?

Yes, that's exactly what I ended up doing. I just didn't realize that was an option until pwired provided the link to the other thread.

  • Like 1

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
×
×
  • Create New...