Infinite Recursion… Hmmm

So, working on the template loader – I’m finally on the right track with this project 🙂

All seems to be going well, I have it set up to try and load the extended version before going for the default template. But, there is a small catch… when the custom template extends the default template things get a bit messy. Because of the way the loaders are set up, the loader looking for extended templates always runs first when searching for any template. So, the new template loader looks for template_name + _extended each template load… this means that each time a template is loaded the _extended version is loaded first.

This at first seems like exactly what we want, but when the extended template extends the original… well, the new loader runs first and reloads the extended template – which extends the original, so reloads the extended version using the new loader, etc. So, it gets into an infinite loop of loading the same extended template.

I’m thinking that there would be a couple of ways to fix this:

  1. load from a special extended templates directory structure (but this could lead to the same problem, only in a different directory)
  2. have a set of default templates and used templates, then only extend the defaults (the regular templates would also extend the defaults, there just would be no changes – but then why not just have defaults & extensions?)
  3. know what template is calling the loader and if it is requesting the same template then don’t load using the extension loader (this seems to be the best & cleanest option to me as it gets rid of the need for extra template files and solves the infinite recursion problem – now, to figure out how to do this)
  4. or I could do this a bit backwards, have the special template loader remove the _extended part of the template_name and change all of the url redirects to template_name_extended – but this doesn’t seem very clean, it would keep the number of files down though
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s