tags:

views:

71

answers:

2

I'm looking at the PHP code for the interspire shopping cart and they make extensive use of template variables such as %%GLOBAL_variables%% and %%variable%%.

I haven't seen those before and I'm trying to understand how they are defined and used. Does anyone know what template engine is involved and any documentation on it?

thanks

+2  A: 

I've used %% as "delimiters" for my own homegrown templating engine. There is nothing special about it, they are just characters that will prevent any unwanted replacements since it is very unlikely they will occur naturally. Some engines use {keyword}, like Smarty. As an example, you can do a quick search/replace with an associative array of data.

$data_replace = array('%%GLOBAL_variable%%'=>'some data', 
    '%%variable1%%'=>'different data', 
    '%%variable2%%'=>'limited time only!');
//Perform the search and replace
$output = str_replace(array_keys($data_replace), $data_replace, $template_text);
Brent Baisley
A: 

As a guess it looks like a home grown solution.

That said, it would be pretty easy to re-create something like this by doing something like:

  1. Load the template file into a string.

  2. Grab all occurances of '%%xxx%%'. (I'm guessing the '%%' are just handly delimiters.)

  3. Convert the first '%%' to '$_' if the occurance begins with '%%GLOBAL' or '$' otherwise.

  4. Once all that's done evaluate the resultant string. (eval)

Additionally, it would be possible to include variables within the scope of the evaluation using extract.

Irrespective, I'd have thought you should be able to confirm this by having a hunt around in the code.

middaparka
-1 for needless eval
just somebody
True - you could replace the '%%xxx%%' with the pre-evaluated variable contents in step 3. This would be safer, but more restrictive. (An advisible good trade off in such circumstances.)
middaparka