Skip to main content
Topic: Extending the template (Read 1463 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Extending the template

While taking a shower I got an idea (of course nothing new, but it finally surfaced in my mind lol): why not use "special tags" in the template to be replaced (for the moment likely in the buffer) with pieces of template?

I know what you are thinking: "what the heck is this guy trying to say?".
Well, an example. :P

The current code:
Code: [Select]
	// Skip nav link.
echo '
<div id="top_section">
<div class="wrapper">';

call_template_callbacks('th', $context['theme_header_callbacks']);

echo '
</div>
<div id="header" class="wrapper', !empty($settings['header_layout']) ? ($settings['header_layout'] == 1 ? ' centerheader' : ' rightheader') : '', '"', empty($context['minmax_preferences']['upshrink']) ? '' : ' style="display: none;" aria-hidden="true"', '>

Possible code:
Code: [Select]
	// Skip nav link.
echo '
<div id="top_section">
<div class="wrapper">
<integrateThemeHeader />
</div>
<div id="header" class="wrapper', !empty($settings['header_layout']) ? ($settings['header_layout'] == 1 ? ' centerheader' : ' rightheader') : '', '"', empty($context['minmax_preferences']['upshrink']) ? '' : ' style="display: none;" aria-hidden="true"', '>

Then, the "<integrateThemeHeader />" will be replaced before sending out the template to the browser with code added by addons.

Yeah, it's not that different, but it gives some nice advantage, allowing easy duplication of "blocks" around in the page and less headaches with functions having to respect naming conventions, etc.

Just an idea I had few minutes ago, so not really developed. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: Extending the template

Reply #1

Then you are doing a lot of str_replace() instead of doing a regular function call. Unless, you cache that. If you are going to do that, why not just use a template system?

 

Re: Extending the template

Reply #2

I will not understand a single line of code if I have to look for "the template" in a dozen different places.  :-[

Sure it was under the shower? On the toilet one has the best ideas, they say!  ;D