Using {title} variable in function?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
Tealon

Using {title} variable in function?

Post by Tealon »

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}
SimonSchaufi

Re: Using {title} variable in function?

Post by SimonSchaufi »

Last edited by SimonSchaufi on Mon Jul 09, 2007 2:07 pm, edited 1 time in total.
Tealon

Re: Using {title} variable in function?

Post by Tealon »

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.
cyberman

Re: Using {title} variable in function?

Post by cyberman »

Have you tried to capture title tag?

http://smarty.php.net/manual/en/languag ... on.capture
Tealon

Re: Using {title} variable in function?

Post by Tealon »

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?
Last edited by Tealon on Tue Jul 10, 2007 1:07 pm, edited 1 time in total.
cyberman

Re: Using {title} variable in function?

Post by cyberman »

Tealon wrote:       {if file_exists("images/cms/$title.gif")}
Are you sure file_exists() is a Smarty function ;)? And you need a Smarty function ...

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).
Tealon

Re: Using {title} variable in function?

Post by Tealon »

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.
Last edited by Tealon on Tue Jul 10, 2007 2:51 pm, edited 1 time in total.
alby

Re: Using {title} variable in function?

Post by alby »

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?
And this?
{capture name=pakken assign=titlecap}images/cms/{title}.gif{/capture}


 
    {myudt img=$titlecap}
 
UDT myudt:
if (file_exists($params['img']))
  echo '';
else
  echo ''.$params['img'];
Alby
Last edited by alby on Tue Jul 10, 2007 3:57 pm, edited 1 time in total.
Tealon

Re: Using {title} variable in function?

Post by Tealon »

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?
Last edited by Tealon on Tue Jul 10, 2007 4:15 pm, edited 1 time in total.
alby

Re: Using {title} variable in function?

Post by alby »

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?
try with: {capture name=pakken assign=titlecap}images/cms/{title}.gif{/capture}

Alby
Tealon

Re: Using {title} variable in function?

Post by Tealon »

That wat it!

Thanx Alby!
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: Using {title} variable in function?

Post by blackhawk »

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???
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: Using {title} variable in function?

Post by blackhawk »

With the title being [don't], This didn't work for me...

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}
So I'm cool!
Locked

Return to “Developers Discussion”