Below is a snippet from class.complier.php lines 89 - 92 that I had to modify in order to restore a syntax compatibility with Smarty (which when used results in major performance improvements in template code.)
89: //THIS BREAKS AN IMPORANT SMARTY FEATURE { $foo_list[$bar.foo_list_entry_id].foo_list_entry_name }
90: //$this->_var_bracket_regexp = '[[\$|#]?\w+#?]';
91: //GOING BACK TO ORIGINAL SMARTY VERSION AT COST OF NO CONFIG VARS!
92: $this->_var_bracket_regexp = '[\$?[\w.]+]';
I'm not currently using config vars so going back to the Smarty version of the regex works for me (for now), but obviously there is probably just a better regular expression that could handle both the config var sntax and the variable indexed array syntax, someone just needs to come up with it. (and/or the accompanying extra variable parsing logic) Since I didn't need config vars I didn't invest much time into such a solution, but wanted to post this here so that it can be addressed as its a vital failure for the 'out-of-box' templatelite code.
Just in case I haven't explained the problem clearly. (though I imagine this has to have come up in many compatibility tests) below is an (extremely basic) 'real world' example:
-----user_list.php
get_all_users(); // returns 'SELECT * FROM users' as array of assoc db rows. /* * $all_users = array( 25 => array( 'user_id'=>25, 'first_name'='joe', 'last_name'=>'schmoe', 'role_id'=>3 ), * 35 => array('user_id'=>35, 'first_name'='jane', 'last_name'=>'doe', 'role_id'=>1 ), * ...); */ $all_roles = $permission_object->get_all_roles(); // returns 'SELECT * FROM roles' as array of assoc db rows (indexed by role_id). /* * $all_users = array( 1 => array('role_id'=>1, 'role_name'='Administrator' ), * 2 => array('role_id'=>2, 'role_name'='Moderator' ), * 3 => array('role_id'=>3, 'role_name'='Basic User' ), * ...); */ $templatelite_obj->assign('users', $all_users); $templatelite_obj->assign('roles', $all_roles ); $templatelite_obj->display( 'user_list.tpl' ); ?>-----user_list.tpl
| Name | Role |
|---|---|
| {$user.first_name} {$user.last_name} | {$roles[$user.role_id].role_name} |
Anonymous
example php script snippet (more readable than inline version above)
Logged In: YES
user_id=1738908
Originator: YES
Yikes, the automatic line breaks make that dificut to ready.
Also, in my rush to type out a 'real world example', I miss-named a variable. -in user_list.php the second comment block was meant to show the results of the get_all_roles(); function call. So that variable name should've been $all_roles not $all_users, from the comment block above.
File Added: user_list.php
Logged In: YES
user_id=1738908
Originator: YES
File Added: user_list.tpl
example template snippet (more readable than inline version above)
snippet from my class.compiler.php which resolved the issue (more readable than inline version above)
Logged In: YES
user_id=1738908
Originator: YES
File Added: class.compiler.php
This has been resolved in the upcoming release 2.20 January 1st 2018. Please see the following code example:
The example is actually showing a new feature (Object Member Accessor). Object Members are not usable in Array Index Accessors yet. This is a planned improvement.