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...
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 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}
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!
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
In my Smarty 3 template I have this code:
{$a=8.34}
{$b=8.33}
{$a-$b|round:2}
Expected result is: 0.01
But I receive this: 0.0099999999999998
Does anybody know how to fix this?
Smarty2 applied the modifier to the result of the complete expression.
Smarty3 does it just on the direct prepending value.
So in Smarty3 you have to use brackets:
{($a-$b)|round:2}
That should solve it.