Jump to content

$config->defaultTemplateFile


Nico Knoll
 Share

Recommended Posts

Hey,

I would love to have something like $config->defaultTemplateFile in the config.php.

What it should do:

If set to "true" every template (except admin of course) should use the defined template file instead of its own. If you want to use another file (or the default file like page.php for page) you have to define it as "alternate template filename".

Advantage:

It's great if you're using a ajax driven site if you don't have to set every template to use e.g. "main.php" or "app.php" or whatever.

What do you guys think?

-- Nico

  • Like 3
Link to comment
Share on other sites

+11.

Nope, not a typo -- just how much I want this to happen.

I'm not much of a fan of AJAX driven sites, but I do tend to implement template level front controller pattern to all the sites I work on. Being able to route all requests to specific file without having to define that file separately to each and every template as an alternate template file would be very, very nice addition. 

  • Like 3
Link to comment
Share on other sites

public function ready(){
    if(wire("page")->template == "admin") return;
    wire("page")->template = "ajax";
}

done. Not sure about consequences. Page viewable is set by if template exists or not.

  • Like 3
Link to comment
Share on other sites

  • 2 months later...

Nico, I like what you are getting at, but think an option like that might be a source of confusion because it would change the entire way that templates work, as well as the way that viewability is determined. Most likely this would be problematic for PW's internal templates and logic. What I would suggest instead is repurposing of the existing $config->appendTemplateFile option and letting that serve is your defaultTemplateFile. In order to make sure that PW considers your page viewable, you'd still have to have a file for the template, but it could be completely blank. 

While I'd prefer the method mentioned above, another alternative would be to automatically populate the altFilename property of every template that you wanted to behave this way. For example, in your /site/templates/admin.php file you could add something like this:

foreach($templates as $template) {
  if($template->flags & Template::flagSystem) continue; 
  if($template->filenameExists()) continue;
  $template->altFilename = 'ajax.php';
  $template->save();
}
  • Like 4
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...