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!
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 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...
I don't know if this can be classified as a bug, so I am sorry if this is posted in the wrong section.
I am trying to make the following work:
{if (preg_match("/Nokia308/i",$info) || preg_match("/Nokia309/i",$info))}
...CONTENT...
{/if}
With no joy result, however:
{if preg_match("/Nokia308/i",$info)}
{if preg_match("/Nokia309/i",$info)}
...CONTENT...
{/if}
{/if}
Works even though it is very messy coding.
Basically I want to display some content if preg_match("/Nokia308/i",$info) or preg_match("/Nokia309/i",$info) is set.
I can't see what I am doing wrong, could anybody shed some light on this?
Thanks.
I don't know what exactly you want to achieve but using:
(preg_match("/Nokia308/i",$info) || preg_match("/Nokia309/i",$info)
condition, you want to make this condition true if the $info variable contains Nokia308 or Nokia309 case-insensitive.
So if you assign:
$smarty->assign('info','Nokia307');
no ...CONTENT... string will be displayed but if you assign:
$smarty->assign('info','Nokia308');
or
$smarty->assign('info','Nokia309');
or
$smarty->assign('info','NOKIA308');
...CONTENT... string will be displayed.
So everything is working here as it should.
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