Re: [SMARTY] how to use a function inside brackets?
| From: | messju mohr | Date: | Mon, 17 Mar 2003 15:21:23 +0000 |
| Subject: | Re: [SMARTY] how to use a function inside brackets? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8696@lists.php.net to get a copy of this message | ||
On Mon, Mar 17, 2003 at 03:57:54PM +0100, philippe.morange@ca-indosuez.com wrote:
> Hi, I don't if this has been already discussed, but I didn't find related material
> about this...
> I made a custom function that outputs a random number between two numbers.
> For example, if I do {random in=5 out=10} it will output 8...
>
> what I want to do is display a random image.
> My images are numbered like that:
> img1.gif
> img2.gif
> img3.gif
>
> In HTML I do <img src="img{random in=1 out=3}.gif"> and it works fine.
>
> But I am using this in a file I include (I specify the image name):
> {include file="menu_element.tpl" menu_img="Image.gif"
> menu_text="Network diagram"}
>
> How could I use my random function in that case?
> I can't do the following:
> {include file="menu_element.tpl" menu_img="img{random in=1 out=3}.gif"
> menu_text="Network diagram"}
>
> I found a workaround:
> {random in=1 out=3 outputToVar=true}
> {include file="menu_element.tpl" menu_img="img$random_number.gif"
> menu_text="Network diagram"}
> And in my function, if outputToVar is set to true I assign the result to a var instead of
> outputting it...
>
> My workaround works, but I thinks it kind of sucks...
call your "outputToVar" "assign" and give it the name of the variable
to assign to. then it works like {include}, {insert} and maybe a few
other built-in php-function i cannot remember at the moment. i don't
think it sucks then, but fits pretty well to smarty.
alternatetivly you can:
{capture name="bla"}{your_function}{/capture}
{assign var=foo value=$smarty.capture.bla}
which sucks more.
have fun
messju
> Do you have any suggestion of how I should do that?
> I really would be great to ba able to use curly brackets inside curly brackets !!!
>
> Thanks,
> Philippe.