Using {title} variable in function?
Using {title} variable in function?
I have the following code to get a specific header image on my website using the {title} variable. Unfortunately the code does not work right. The $title variable is not replaces like i am used to with the smarty engine. Can someone help me on how to implement the variable right?
{if file_exists("images/cms/$title.gif")}
{else}
{/if}
{if file_exists("images/cms/$title.gif")}
{else}
{/if}
Re: Using {title} variable in function?
http://forum.cmsmadesimple.org/index.ph ... l#msg62798
or
http://forum.cmsmadesimple.org/index.ph ... l#msg62797
or
http://forum.cmsmadesimple.org/index.ph ... l#msg62797
Last edited by SimonSchaufi on Mon Jul 09, 2007 2:07 pm, edited 1 time in total.
Re: Using {title} variable in function?
This is not what I'm asking. If look at my code, you see that the problem is the if_exists function. I want to use the {title} variable in the function, because {title} can not be nested in a smarty tag and $title does not work, because its somehow not related to {title}.
and b.t.w. i have searched, and red all the topics you gave me.
and b.t.w. i have searched, and red all the topics you gave me.
Re: Using {title} variable in function?
I have tried this code, but it also does not work:
{capture name=pakken assign=titlecap}
images/cms/{title}.gif
{/capture}
{if file_exists($titlecap)}
{else}
{$titlecap}
{/if}
Does someone know what I'm doing wrong?
{capture name=pakken assign=titlecap}
images/cms/{title}.gif
{/capture}
{if file_exists($titlecap)}
{else}
{$titlecap}
{/if}
Does someone know what I'm doing wrong?
Last edited by Tealon on Tue Jul 10, 2007 1:07 pm, edited 1 time in total.
Re: Using {title} variable in function?
Are you sure file_exists() is a Smarty functionTealon wrote: {if file_exists("images/cms/$title.gif")}

If you wanna use php inside Smarty you have to mask it with {php}{/php} and activate the use in config.php (use_smarty_php_tags).
Re: Using {title} variable in function?
Again is the $title variable not recognized and the file_exists function is therefore not working.
Maybe another way is possible. Where does the smarty module assigns the value to {title}? I think it is easier to do the file_exist check there and pass a variable on to the template with true or false.
@edit:
I worked on this problem for a few hours today, and tried a UDF. But again the function file_exists is not taking any variable, while a direct string to the file is no problem....
So can anyone tell me why it is working with the sting and not with the variable?
Btw: i checkes the content of the variable a lot of times en its always oke.
Maybe another way is possible. Where does the smarty module assigns the value to {title}? I think it is easier to do the file_exist check there and pass a variable on to the template with true or false.
@edit:
I worked on this problem for a few hours today, and tried a UDF. But again the function file_exists is not taking any variable, while a direct string to the file is no problem....
So can anyone tell me why it is working with the sting and not with the variable?
Btw: i checkes the content of the variable a lot of times en its always oke.
Last edited by Tealon on Tue Jul 10, 2007 2:51 pm, edited 1 time in total.
Re: Using {title} variable in function?
And this?Tealon wrote: I have tried this code, but it also does not work:
{capture name=pakken assign=titlecap}
images/cms/{title}.gif
{/capture}
{if file_exists($titlecap)}
{else}
{$titlecap}
{/if}
Does someone know what I'm doing wrong?
UDT myudt:{capture name=pakken assign=titlecap}images/cms/{title}.gif{/capture}
{myudt img=$titlecap}
Albyif (file_exists($params['img']))
echo '';
else
echo ''.$params['img'];
Last edited by alby on Tue Jul 10, 2007 3:57 pm, edited 1 time in total.
Re: Using {title} variable in function?
Same problem again. With $params['img'] in the file_exists function it does not work. When I echo the $params['img'] out and use the printed string in the file_exists, it does not work..... Looks like the file_exists function can not take up a variable somehow...
@edit:
While I was just trying stuff out i cam across something very strange. A var_dump of the variable gives in the source code this:
string(22) "images/cms/Home.gif
"
It looks like a enter in the string.... This is new for me. Has anyone encountered this before?
@edit:
While I was just trying stuff out i cam across something very strange. A var_dump of the variable gives in the source code this:
string(22) "images/cms/Home.gif
"
It looks like a enter in the string.... This is new for me. Has anyone encountered this before?
Last edited by Tealon on Tue Jul 10, 2007 4:15 pm, edited 1 time in total.
Re: Using {title} variable in function?
try with: {capture name=pakken assign=titlecap}images/cms/{title}.gif{/capture}Tealon wrote: Same problem again. With $params['img'] in the file_exists function it does not work. When I echo the $params['img'] out and use the printed string in the file_exists, it does not work..... Looks like the file_exists function can not take up a variable somehow...
@edit:
While I was just trying stuff out i cam across something very strange. A var_dump of the variable gives in the source code this:
string(22) "images/cms/Home.gif
"
It looks like a enter in the string.... This is new for me. Has anyone encountered this before?
Alby
Re: Using {title} variable in function?
I'm having a small problem with this technique - capture automatically escapes single quotes found in titles. so you can't do conditional statements the way you want. for example, put in
[don't]
as a page title
and then capture that title variable, you can't compare it to variable value [don't] from another array.
anyway around this???
[don't]
as a page title
and then capture that title variable, you can't compare it to variable value [don't] from another array.
anyway around this???
Re: Using {title} variable in function?
With the title being [don't], This didn't work for me...
but this did...
So I'm cool!
Code: Select all
{capture assign="mtitle"}{title}{/capture}
<p>
{foreach from=$mstats item=entry}
{if $entry.team == $mtitle}
Season Record: <b>{$entry.record}</b>
{/if}
{/foreach}
</p>
but this did...
Code: Select all
{strip}
<p>
{foreach from=$mstats item=entry}
{if ($entry.team == $content_obj->Name())}
Season Record: <b>{$entry.record}</b>
{/if}
{/foreach}
</p>
{/strip}