phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

<!-- RESOURCE --> template tag

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The next feature release of phpBB 3 will be 3.1/Ascreaus followed by 3.2/Arsia.

<!-- RESOURCE --> template tag

Postby Arty » Tue Feb 14, 2012 11:08 am

edit: abandoned and moved from RFC to discussion.

This RFC requires merge of [RFC] Merge style components

Introduction
With style components separation gone, it might be a good idea to apply template inheritance to everything: templates, css files, javascript. I suggest to add new template instruction: <!-- RESOURCE filename -->

It takes only one parameter: name of file. It might be string, it might be template variable:
Code: Select all
<!-- RESOURCE 'template/mystuff.js' -->
<!-- RESOURCE IMG_LOGO -->

Template checks if file exists, outputs its file name. If it doesn't exist and style has a parent style, it outputs file name for parent style.

Sample output:
Code: Select all
./styles/whatever/template/mystuff.js
./styles/whatever/theme/images/logo.png


Advantages
  • Allows to apply template inheritance to everything
  • No need for variables like S_SUPER_TEMPLATE_PATH to include scripts: if script exists in current style, it will be included. If it doesn't exist, script from parent style will be included


Possible addition
Instead of one parameter, it could take several parameters, separated by spaces. Then all parameters would be merged into one big string before checking for file name. That would allow mixing strings and template variables, like
Code: Select all
<!-- RESOURCE 'images/' forumrow.FORUM_IMAGE '.png' -->
that will result in
Code: Select all
$resource = 'images/' . $_forumrow_val['FORUM_IMAGE'] . '.png';
and then checked against existing files and prepended './styles/whatever/' before echoing file name.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: [RFC] <!-- RESOURCE --> template tag

Postby MichaelC » Tue Feb 14, 2012 11:31 am

EDIT: Doesn't matter, I mis-read this.

Now, I'm not really sure of why this would be helpful, can you show an example use-case?
Unknown Bliss
psoTFX wrote:I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"

No unsolicited PMs please except for quotes.
User avatar
MichaelC
Website Team
Website Team
 
Posts: 797
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] <!-- RESOURCE --> template tag

Postby Arty » Thu Feb 16, 2012 11:06 am

Unknown Bliss wrote:Now, I'm not really sure of why this would be helpful, can you show an example use-case?

Including javascript and css files.

Currently to use template inheritance for javascript files, instead of T_TEMPLATE_PATH templates should use T_SUPER_TEMPLATE_PATH, like this:
Code: Select all
<script src="{T_SUPER_TEMPLATE_PATH}/editor.js" />

If style author would want to include editor.js in his style, he has to change it to
Code: Select all
<script src="{T_TEMPLATE_PATH}/editor.js" />

Same could be applied to theme, except that there is no T_SUPER_THEME_PATH variable, so template inheritance can't be used for CSS files.

With "resource" tag template could use
Code: Select all
<script src="<!-- RESOURCE 'template/editor.js' -->" />

then phpBB will look for template/editor.js in current style and if it doesn't exist, it will link to template/editor.js in its parent style.

This tag makes it possible to use template inheritance for js and css files.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: [RFC] <!-- RESOURCE --> template tag

Postby callumacrae » Thu Feb 16, 2012 2:02 pm

What we *could* use is something to automatically include the script in the footer. Eg:

Code: Select all
<!-- SCRIPT 'template/editor.js' -->


Would include the script after jQuery.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 883
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC] <!-- RESOURCE --> template tag

Postby brunoais » Thu Feb 16, 2012 3:51 pm

callumacrae wrote:What we *could* use is something to automatically include the script in the footer. Eg:

Code: Select all
&lt;!-- SCRIPT 'template/editor.js' --&gt;


Would include the script after jQuery.

Hum... Pushing too much to the bottom will force the page to take longer to load. Ppl could get upset because all the page is there but everything that uses js is still not working. Also, if you place all that at the bottom of the page you cannot use the advantage of DOMContentLoaded properly. Images take way longer to load than the js files. With all the avatars in a single page (think the bigger avatars (in file size)) js may only start loading 1 or even 2 seconds after the page is loaded. Hum... I'm getting too much into that topic again. :?
brunoais
Registered User
 
Posts: 626
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] <!-- RESOURCE --> template tag

Postby callumacrae » Thu Feb 16, 2012 3:54 pm

brunoais wrote:
callumacrae wrote:What we *could* use is something to automatically include the script in the footer. Eg:

Code: Select all
&lt;!-- SCRIPT 'template/editor.js' --&gt;


Would include the script after jQuery.

Hum... Pushing too much to the bottom will force the page to take longer to load. Ppl could get upset because all the page is there but everything that uses js is still not working. Also, if you place all that at the bottom of the page you cannot use the advantage of DOMContentLoaded properly. Images take way longer to load than the js files. With all the avatars in a single page (think the bigger avatars (in file size)) js may only start loading 1 or even 2 seconds after the page is loaded. Hum... I'm getting too much into that topic again. :?

…either you have a blank page for a few seconds, or a page that you can't use the JavaScript of for a few seconds. I know which I would prefer. Images are asynchronous.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 883
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC] <!-- RESOURCE --> template tag

Postby Arty » Thu Feb 16, 2012 5:42 pm

How about this?
Code: Select all
<!-- BEGINSCRIPT -->
<script src="<!-- RESOURCE 'template/editor.js' -->"></script>
<script>
Some inline script here
</script>
<!-- ENDSCRIPT -->

All data between those tags will be buffered, then in overall_footer.html before </body> another command:
Code: Select all
<!-- SCRIPTS -->
</body>
</html>
that will echo buffered data.

If for some reason script must be included in middle of file, for example, if script is badly coded and it writes something with document.write() or if its some counter or ads, script can be included usual way without <!-- BEGINSCRIPT --> and <!-- ENDSCRIPT -->, so it won't be buffered.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: [RFC] <!-- RESOURCE --> template tag

Postby Arty » Thu Feb 16, 2012 5:51 pm

Also, alternative suggestion for resource tag: instead of using tag, catch all entries of {T_STYLE_PATH}, like this:
Code: Select all
<img src="{T_STYLE_PATH}/images/logo.png" />
template system on finding {T_STYLE_PATH} will grab all data from } to next " or ' (in this case "/images/logo.png"), locate file based on styles tree and output path to it. Path will be hardcoded on compilation to avoid checking for files on every page load.

Example of current compiled code:
Code: Select all
<img src="<?php echo (isset($_rootref['T_STYLE_PATH'])) ? $_rootref['T_STYLE_PATH'] : ''; ?>/images/logo.png" />

Example of what it will look like:
Code: Select all
<img src="<?php ob_start(); ?>/images/logo.png<?php $link = ob_end_clean(); echo $this->locate_resource($link); ?>" />

Function locate_resource() will check for files that match $link in styles tree, if not found it will echo "styles/current_style_path" + $link.

For style authors it will look like usual template variable, so they won't get confused with even more style tags, but it will behave differently.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Re: [RFC] <!-- RESOURCE --> template tag

Postby brunoais » Thu Feb 16, 2012 7:43 pm

callumacrae wrote:…either you have a blank page for a few seconds, or a page that you can't use the JavaScript of for a few seconds. I know which I would prefer. Images are asynchronous.

The option you forgot. Deferring execution of js and place its tags in the head.
Arty wrote:...
Example of what it will look like:
Code: Select all
<img src="<?php ob_start(); ?>/images/logo.png<?php $link = ob_end_clean(); echo $this->locate_resource($link); ?>" />

Function locate_resource() will check for files that match $link in styles tree, if not found it will echo "styles/current_style_path" + $link.

For style authors it will look like usual template variable, so they won't get confused with even more style tags, but it will behave differently.

I like your alternative. Anyway, you don't need ob_* for that: We can translate that to something like:
before:
Code: Select all
<img src="{T_STYLE_PATH}/images/logo.png" />

After:
Code: Select all
<img src="<?php echo $this->locate_resource('/images/logo.png')?>"  />


That code is much simpler to execute. Believe me. This option can take a little more resources to process and create that php code than your way. Anyway, it is faster to execute and I believe that the execution part is the one that really matters and not so much the caching of the template.
brunoais
Registered User
 
Posts: 626
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] <!-- RESOURCE --> template tag

Postby Arty » Thu Feb 16, 2012 7:49 pm

No, ob_ stuff is there for a reason: to allow use of template variables. For example:
Code: Select all
<img src="{T_STYLE_PATH}/theme/images/folder_{topicrow.FOLDER_TYPE}.png" />


edit:
Actually, never mind ob_ stuff. With it files have to be located during template execution. Without it files can be located during template compilation, reducing resources usage.
Formerly known as CyberAlien.
User avatar
Arty
Styles Team
Styles Team
 
Posts: 796
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars

Next

Return to [3.x] Discussion

Who is online

Users browsing this forum: No registered users and 15 guests