RE: Assigning to variables
| From: | Lambert, Patrick | Date: | Wed, 18 Aug 2004 21:44:17 +0000 |
| Subject: | RE: Assigning to variables | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-11706@lists.php.net to get a copy of this message | ||
Capture should work...
http://smarty.php.net/manual/en/language.builtin.functions.php#LANGUAGE.FUNC
TION.CAPTURE
You can dynamically name your capture by concatenating the section index
value into it....
{section name=dataloop loop=$data}
{capture name="cap"|cat:$smarty.section.dataloop.index}
{$data[dataloop].FOO}
{/capture}
{/section}
{$smarty.capture.cap0}
{$smarty.capture.cap1}
p.
> ----------
> From: Jake Stride
> Sent: Wednesday, August 18, 2004 5:18 PM
> To: smarty-general@lists.php.net
> Subject: Assigning to variables
>
> I have had a look at the faqs and done a search on google, but can't seem
> to
> solve this question.
>
> I have a template that iterates over an array using a section, the problem
> is that I would like to parse some of the variables so that I can use them
> later on in the template. Below is a cut down version of the template:
>
> {section name="view" loop=$view_data}
>
> {if isset($view_data[view].newmodule)}<a
> href="{$serverRoot}/?{$sessionName}={$sessionValue}&module={$view_data
> [v
> iew].newmodule}&function={$view_data[view].newfunction}&sub={$view
> _d
> ata[view].newsub}&type={$view_data[view].newtype}&view={$view_data
> [v
> iew].newview}&id={$view_data[view].newid}"><img class="new"
> src="{$serverRoot}/themes/{$theme}/graphics/news.gif"
> alt="{$view_data[view].newname}" /></a>{/if}
>
> {/section}
>
> What I want to do is something like:
>
> {section name="view" loop=$view_data}
>
> {assign var="uselater" value="}<a
> href="{$serverRoot}/?{$sessionName}={$sessionValue}&module={$view_data
> [v
> iew].newmodule}&function={$view_data[view].newfunction}&sub={$view
> _d
> ata[view].newsub}&type={$view_data[view].newtype}&view={$view_data
> [v
> iew].newview}&id={$view_data[view].newid}"><img class="new"
> src="{$serverRoot}/themes/{$theme}/graphics/news.gif"
> alt="{$view_data[view].newname}" /></a>"}
>
> {/section}
>
> ...
>
> {$uselater}
>
> Obviously this doesn't work so is there some way around this or do I need
> to
> use another template?
>
> Thanks
>
> Jake
>
>