Search code examples
smarty

Smarty Combine internal get variable with another value


I'm trying to build a foreach loop in smarty where i have to access specific get vars like "user_1", "user_2" etc to mark checkboxes as checked. So what i need is smth like

{if $smarty.get.user_{$foreach_current_user_id} == "on"}checked{/if}

but this doesn't work. Is there a way to pass the loop variable to the get variable? I've haven't found smth on the internet yet...

Thanks if someone knows a solution


Solution

  • The easiest way is to create a variable with the desired name:

    {$user_name='user_'|cat:$foreach_current_user_id}
    {if $smarty.get.$user_name == "on"}checked{/if}