[go: up one dir, main page]

Menu

#39 Current _var_bracket_regexp breaks vital syntax compablty

v2.20
closed
8
2017-12-24
2008-02-07
junky
No

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

Current users

{foreach from=$users item=$user} {/foreach}
Name Role
{$user.first_name} {$user.last_name} {$roles[$user.role_id].role_name}

Add new user

<form action="/add_user.php"> First name:<input type="text" name="first_name"> Last name:<input type="text" name="last_name"> <select name="role_id"> {foreach from=$roles key=$role_id item=$role } <option value="{$role_id}">{$role_name}</option> {/foreach} </select> <input type="submit"> </form>

Discussion

  • junky

    junky - 2008-02-07

    example php script snippet (more readable than inline version above)

     
  • junky

    junky - 2008-02-07

    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

     
  • junky

    junky - 2008-02-07

    Logged In: YES
    user_id=1738908
    Originator: YES

    File Added: user_list.tpl

     
  • junky

    junky - 2008-02-07

    example template snippet (more readable than inline version above)

     
  • junky

    junky - 2008-02-07

    snippet from my class.compiler.php which resolved the issue (more readable than inline version above)

     
  • junky

    junky - 2008-02-07

    Logged In: YES
    user_id=1738908
    Originator: YES

    File Added: class.compiler.php

     
  • Don Duvall

    Don Duvall - 2017-11-17

    This has been resolved in the upcoming release 2.20 January 1st 2018. Please see the following code example:

    {$dog->Attributes[$attr_ids.hair]->Length}  //Legal
    {$dog->Attributes[$attr_ids->hair]->Length} //Illegal
    

    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.

     
  • Don Duvall

    Don Duvall - 2017-11-17
    • status: open --> pending
    • assigned_to: Don Duvall
     
  • Don Duvall

    Don Duvall - 2017-11-17
    • Group: Current_Version --> v2.20
     
  • Don Duvall

    Don Duvall - 2017-12-24
    • status: pending --> closed
     

Anonymous
Anonymous

Add attachments
Cancel