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
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}
Related
I want to access the data of the object that comes as a smarty variable according to the variable I have defined.
I'm actually expecting like {$page->page_meta->description} as I wrote below. But nothing happens. It doesn't give an error. What is the problem?
Ok now I understand what you mean.
{foreach $metas as $meta}
{$page->page_meta->{$meta}}
{/foreach}
PS next time do not insert screenshots like this but write code
I'm trying to modify a template in a simple manner, not rewrite the underlying code. I realize normally object assignment is not done in the template, but is it possible?
I want something like this:
{if $product->available_now == "XXX001"}
{assign var="product->available_now" value={"YYY123"}}
{/if}
I want to read the object variable $product->available_now and, based on its contents, update it to something else for use later down in the template.
Everything I try ends up with either a blank screen or else (as is the case with my code above) an unchanged variable.
FYI: this is for use with prestashop
Try with:
{if $product->available_now == "XXX001"}
{assign var=product->available_now value="YYY123"}
{/if}
I must confess that I have not tested it but it has to be the error you made, as this is the correct way to assign a value to a variable!
I need to use the variable inside the popup tag from Smarty.
I can't declare the var on the server because it's dynamic (originating from a loop).
I tried all the different approaches with the assign tag like
{assign var=title value="$some_loop_var - sitename!"}
or
{assign var="myfield" value=$some_loop_var + "btn_licencee_select"}
Always the printed variable is empty.
Any ideas what I might be doing wrong?
The solution was quite trivial in the end:
If you use a variable inside a Smarty function you need to "escape" it with backticks:
{popup text="`$some_loop_var`_static_part" }
Hope this helps anybody else as well. Took me hours to figure this out...
in the checkout page, I am trying to pass a variable through step 2 to step 3. I want to check the town of the user and do specific payments methods according to the town of the user.
I tried a lot, but couldn't see the variable. It always returns blank!
In the step 2, (this is the page with the address and everything about the user-client) I did this:
{assign var="town" value="$user_state"}
How can I pass this variable to step 3? (file name is payment_methods.tpl)
*I read something about smarty...
I tried {php} code...
Any help? thanks in advance!
ok I found a solution to my problem.
Inside the step_profile_fields.tpl file, I have done my calculations and capture this variable, for example:
{capture name="state_of_user"}{$ship}{/capture}
In step 4, I have included the previous tpl file (step_profile_fields.tpl)
and grab this value through:
$smarty.capture.state_of_user
For example I have this:
{include file=".." user=$smarty.capture.state_of_user}
if someone need more help. please let me know!
Hi I am trying to evaluate a variable from a file and a normal one but seems to be harder than it looks so :
This works:
{config_load file="archive_page.conf"
section="profile"} {include file="header.tpl" title=#pageTitle# keywords=#keywords# description=#description#}
I would like to also use my var and concatenate the text together so the below doesn't work also I have tried variations with '', "" but leads either an error message or one of the variables to display as text...
{config_load file="archive_page.conf"
section="profile"} {include file="header.tpl" title=#pageTitle#$MYVARHERE keywords=#keywords# description=#description#}
I tried various things but I can't get it to work, any help is much appreciated.
use the cat variable modifier:
title=#pageTitle#|cat:$MYVARHERE