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
Related
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!
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...
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
Looking through the Smarty debug console I discovered the variable {$u}, which contains the array video => "".
{$u} also contains photo, interview, etc. which is taken from the t1 table in the database. The database does have a url in the video column, but it is not being captured in {$u}. The problem right now is that I can't figure out where {$u} is populated.
What is the best way to find out where $u is populated?
If you can't debug your code line by line (with Zend or Xdebug), try to search your PHP code for ->assign('u', ->assign("u" or your Smarty templates for {$u=, {assign name="u", etc...
Unfortunatly there is no way to make Smarty tell you automatically where a varible was declared.