[RFC|Accepted] Pre-Compile Template Includes

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
User avatar
Kellanved
Former Team Member
Posts: 407
Joined: Sun Jul 30, 2006 4:59 pm
Location: Berlin

[RFC|Accepted] Pre-Compile Template Includes

Post by Kellanved » Fri Apr 16, 2010 12:28 pm

It is a rather frequent nuisance that MODs need to add a snipped to the template, complicating the installation on styles other than the default. To overcome this limitation, I propose the introduction of a new kind of template variable: A pre-compile insertion region., "<!-- REGION: {NAME} -->". Essentially a template variable that is replaced before the compiler runs, not on run-time.

The concept is that the template compiler calls a hook "template_region", which - if defined in a MOD - returns a template snippet for the given region (header, footer, postrow,...). These snippets are then injected into the template during compilation, allowing the edit-less adaption of template files.

Core Advantages
  • Editless addition of template snippets
  • Eases updates
  • Makes MODs independent of styles
  • Able to respect styles by means of injecting includes
  • Little to no performance hit, as only called in template compile
  • Not too hard to implement
No support via PM.
Trust me, I'm a doctor.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] Pre-Compile Template Includes

Post by Oleg » Fri Apr 16, 2010 12:32 pm

How would you handle two mods supplying data for the same NAME?

How would the template know that a mod supplies such data? Which mod supplies the data?

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Pre-Compile Template Includes

Post by EXreaction » Fri Apr 16, 2010 2:57 pm

Yes, I used something like this for my User Blog Mod along with the hooks.

This is an absolute requirement if you want to see much use of hooks that do not require edits to templates. Areas like the header, footer, viewtopic, posting panels, etc.

User avatar
Kellanved
Former Team Member
Posts: 407
Joined: Sun Jul 30, 2006 4:59 pm
Location: Berlin

Re: [RFC] Pre-Compile Template Includes

Post by Kellanved » Fri Apr 16, 2010 9:10 pm

nn- wrote:How would you handle two mods supplying data for the same NAME?

How would the template know that a mod supplies such data? Which mod supplies the data?
All MODs providing input for a region are called, their snippets concatenated.
No support via PM.
Trust me, I'm a doctor.

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: [RFC] Pre-Compile Template Includes

Post by Highway of Life » Fri Apr 16, 2010 10:29 pm

ExpressionEngine uses something similar to this proposal for their plugins. It is extremely powerful and enables you to create custom plugins that only modify a template and not the core code. Here are some examples: (hopefully this is helpful)

Code: Select all

{exp:hello_world:foo}
Which would call the file: /third_party/hello_world/pi.hello_world.php

Code: Select all

<?php

class hello_world
{
    public function foo()
    {
        return '<p>Hello Foo World!</p>';
    }
} 
Produces:

Code: Select all

<p>Hello Foo World!</p>
You can also include parts of the templates within processing, for example...

Code: Select all

{exp:modify_text:urlencode}
some text to encode.
{/exp:modify_text:urlencode}
And even use loops...

Code: Select all

{exp:people:display}
	<dl>
		<dt>{name}</dt>
		<dd>{address}</dd>
	</dl>
{/exp:people:display}
Plugin files:

Code: Select all

<?php

class modify_text
{
    public function urlencode()
    {
        return urlencode(trim($this->EE->TMPL->tagdata));
    }
} 

Code: Select all

<?php

class people
{
    public function display()
    {
        $results = $this->EE->db->get('people');
        $data = array();

        foreach ($results as $row)
        {
            $data[] = array(
                'name'        => $row['name'],
                'address'    => $row['address'],
            );
        }
        
        return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $data);
    }
} 
Image

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Pre-Compile Template Includes

Post by EXreaction » Sat Apr 17, 2010 12:51 am

Something like that would be useful as well.

I would suggest something like that being supported or allowing for hook directories within the style directory that are auto-loaded if that style is used. That allows some extra neat things to be done for specific templates without affecting all of them (one I used of that style was changing the date/time format for a specific style to fit in much more nicely).

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: [RFC] Pre-Compile Template Includes

Post by Highway of Life » Sat Apr 17, 2010 2:32 am

Hmm... after reading the first post again, I think my request is fairly different. Perhaps I should create an RFC for that kind of template /engine plugin feature?
Image

User avatar
Kellanved
Former Team Member
Posts: 407
Joined: Sun Jul 30, 2006 4:59 pm
Location: Berlin

Re: [RFC] Pre-Compile Template Includes

Post by Kellanved » Sat Apr 17, 2010 11:26 pm

Indeed, HoL: your proposal is about calling functions from within the template. That's already covered by the PHP tag in the template syntax - functionality- and security -wise , there's nothing to be gained by adding a dedicated syntax IMHO.
My proposal is about injecting template code from within a MOD without editing files, allowing the easy addition of output.
No support via PM.
Trust me, I'm a doctor.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Pre-Compile Template Includes

Post by MichaelC » Sun Apr 18, 2010 2:04 pm

I think this would be something good for the modding community but how would they support more than one MOD using that hook?
Formerly known as 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
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Pre-Compile Template Includes

Post by igorw » Sun Apr 18, 2010 2:07 pm

Has been answered a few posts above: viewtopic.php?p=207531#p207531

Post Reply