phpBB Standalone Template Engine

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

Louis7777 wrote:2. Type a small tutorial on how to create language template variables using the above or any other engine? For example:

How would this --> {L_HOME_ADDRESS}

be replaced by this --> MY STREET ADDY

which is defined in a language file like this:

Code: Select all

$language = array_merge($language, array(
   'HOME_ADDRESS' => 'MY STREET ADDY',
));
Assuming you're using twig, the way variables are provided to the template engine is very similar to phpBB's standalone engine. Without looking at how it's actually done for language variables currently, I assume you can simply loop through the $language array and build a new array, prepending each of the keys with L_ when you're sure it's been completely built, just prior to sending it to the engine. Something like:

Code: Select all

$language = array();
$language = array_merge(array(
    'MY_VARIABLE' => 'My text',
), $language);

//...
$final_language = array();
foreach ($language as $key => $value) {
    $final_language["L_$key"] = $value;
}

$twig->render(array_merge($final_language, $other_template_variables));
// Note that because $other_template_variables is second,
// any duplicate keys in $final_language will be overwritten

// var_dump($final_array);
// Output:
/*
array(1) {
  ["L_MY_VARIABLE"]=>
  string(7) "My text"
}
*/
Now just like any other variable, you access it using its name. By default, Twig uses two sets of brackets around its variables, so {{ L_MY_VARIABLE }} would output: My text

It's a rough example but should work for what you need. You can play around with it some here.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
TCR_500
Registered User
Posts: 175
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Re: phpBB Standalone Template Engine

Post by TCR_500 »

Thanks for posting this tutorial. It has proved very helpful and has been presented in a very simplistic way.

I found that you can put the two classes in a namespace if you do the following:

Put this at the beginning of your template file:

Code: Select all

<?php
namespace Name\Of\Namespace;
After that, find in "class template_compile":

Code: Select all

function template_compile(&$template)
And replace that with:

Code: Select all

function __construct(&$template)
Then find:

Code: Select all

$compile = new template_compile($this);
And replace it with:

Code: Select all

$compile = new \Name\Of\Namespace\template_compile($this);
Then, where you have defined:

Code: Select all

$template = new template();
Change that to:

Code: Select all

$template = new \Name\Of\Namespace\template();
User avatar
ViolaF
Registered User
Posts: 1517
Joined: Tue Aug 14, 2012 11:52 pm

Re: phpBB Standalone Template Engine

Post by ViolaF »

sorry, but i found no basic instruction for using 3.1.* template engine here.
the 3.0.* template engine use no namespaces or??
TCR_500
Registered User
Posts: 175
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Re: phpBB Standalone Template Engine

Post by TCR_500 »

Sorry for the very late reply. My last post was for modifying the 3.0.x standalone template engine to use namespaces, not to modify the 3.1.x template engine to be a standalone.
User avatar
MichaelC
Consultant
Consultant
Posts: 3642
Joined: Mon Dec 21, 2009 3:36 pm
Location: Surrey, UK
Name: Michael Cullum
Contact:

Re: phpBB Standalone Template Engine

Post by MichaelC »

ViolaF wrote:sorry, but i found no basic instruction for using 3.1.* template engine here.
the 3.0.* template engine use no namespaces or??
The 3.1 template engine is twig with a lexer for phpBB syntax.
:)
Formerly known as Unknown Bliss.
Formerly Website Team Lead/Manager & Development Team.
Please don't PM me for support (or stuff that belongs in the forums or tracker) but otherwise feel free
User avatar
ViolaF
Registered User
Posts: 1517
Joined: Tue Aug 14, 2012 11:52 pm

Re: phpBB Standalone Template Engine

Post by ViolaF »

thanks, but the more i see from 3.1.* the more i be aware from chosing phpbb as a modder and as a forum software. goodbye great times with 3.0.* :(
Locked

Return to “[3.0.x] MOD Writers Discussion”