Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

add a prefix to a variable name (variable variable)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
BbErSeRkK
Smarty Rookie


Joined: 04 Jan 2008
Posts: 14

PostPosted: Wed Sep 23, 2009 7:14 am    Post subject: add a prefix to a variable name (variable variable) Reply with quote

I have a template that generates a dynamic table for db data

Code:

<table class="tablesorter {$tableclass}" cellspacing="0" cellpadding="0" summary="{$table_caption}" id="{$table_id|default:'tblDispDBTable'}" >
<caption>{$table_caption}</caption>
<thead>
   <tr>
   {section name=hcols loop=$table_header}

i need to use two of these tables on the one page
when i do the include i think i can do
Code:
{include file="tblDynamic.tpl" table_header=$table1_header}

but I was hoping to use a prefix on the variables instead
Code:

<table class="tablesorter {$prefix+$tableclass}" cellspacing="0"

just wondering if this was possible
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 23, 2009 1:20 pm    Post subject: Reply with quote

Not without an intermediate step:

Code:
{assign var="tmp" value="`$prefix`varname"}
{$tmp}
Back to top
View user's profile Send private message Visit poster's website
BbErSeRkK
Smarty Rookie


Joined: 04 Jan 2008
Posts: 14

PostPosted: Thu Sep 24, 2009 4:14 am    Post subject: Reply with quote

Back to top
View user's profile Send private message
BbErSeRkK
Smarty Rookie


Joined: 04 Jan 2008
Posts: 14

PostPosted: Fri Sep 25, 2009 1:23 am    Post subject: Reply with quote

ok for future reference i needed to do this to have it work properly, not sure if there is a better way?

Code:
{assign var=prefixed_table_rows value="`$tbl_prefix`table_rows"|varvar}
..
{section name=drow loop=$prefixed_table_rows}
...
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Sep 25, 2009 2:56 am    Post subject: Reply with quote

Assign names correctly from PHP and just loop with Smarty?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP