ElkArte Community

Title: Extending the template
Post by: emanuele on July 06, 2015, 12:48:27 pm
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. ;)
Title: Re: Extending the template
Post by: Joshua Dickerson on July 06, 2015, 03:01:31 pm
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?
Title: Re: Extending the template
Post by: Jorin on July 07, 2015, 01:11:24 am
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