Page 1 of 1

[solved] question about {eval var=$...}

Posted: Wed Mar 31, 2010 9:10 am
by nicmare
i use this additional content block:

Code: Select all

{content block='Meta Description' oneline='true' assign="metadesc"}{eval var=$metadesc}
this works.
but i want to use the metadesc twice in my template. therefore i use it in the tag and in the tag.
But in body tag i get the error:
string(43) "Smarty error: eval: missing 'var' parameter"

why does that not work?
thanks!

Re: question about {eval var=$...}

Posted: Wed Mar 31, 2010 9:57 am
by Peciura
{content block='Meta Description' oneline='true' assign="temp"}
{eval var=$temp  assign='metadesc'}

{* use it whereever you want *}
{$metadesc}

Re: question about {eval var=$...}

Posted: Wed Mar 31, 2010 10:03 am
by nicmare
Ah allright now i get no error but also no value in my body tag. but it works in the meta tag.
obviously i can use the var just one time in whole template?!

Re: question about {eval var=$...}

Posted: Wed Mar 31, 2010 11:40 am
by Peciura
but also no value in my body tag
Mind, variable should be generated before {content}. I think

Code: Select all

{content block='Meta Description' oneline='true' assign="temp"}
is bellow {content} isn't it ? It would be easier if you attached page template and link to page.

Re: question about {eval var=$...}

Posted: Wed Mar 31, 2010 11:59 am
by calguy1000
CMSMS (since 1.5 IIRC) performs template processing in a non-standard manner.

Given a simplified page template like:

Code: Select all

<__html>
<head>
{metadata}
</head>
</__body>
{content}
<__body>
</__html>
1.  Anything above is processed
2.  The body is processed
3.  The head section is processed
4.  all of the information from the above 3 steps is glued back together and output.

This is done to allow setting variables in the body (i.e:from a module) that can then be used in the head (to do things like set page title etc).
i.e (another simplified example):

Code: Select all

<__html>
<head>
<title>{$mypagetitle}</title>
{metadata}
</head>
</__body>
{content block='mypagetitle' oneline=true assign='mypagetitle'}
{content}
<__body>
</__html>
Notice how 'mypagetitle' is created in the body, and then used in the head section.

Alternatively

Code: Select all

{content block='mypagetitle' oneline=true assign='mypagetitle'}
<__html>
<head>
[color=green]<title>{$mypagetitle}</title>[/color]
{metadata}
</head>
</__body>
[color=green]<h3>{$mypagetitle}</h3>[/color]
{content}
<__body>
</__html>
Notice how mypagetitle is created above the head section, and then used in both the head and the body.

However:  This will not work:

Code: Select all

<__html>
<head>
{content block='mypagetitle' oneline=true assign='mypagetitle'}
<title>{$mypagetitle}</title>
{metadata}
</head>
</__body>
<h3>{$mypagetitle}</h3>
{content}
<__body>
</__html>
This is because the body is processed first, and the head section is processed afterwards, therefore {$mypagetitle} is not set until the head is processed.

Of course in these simplified examples I am not doing any error checking to make sure that somebody actually specified a string in the mypagetitle field in edit content.

This is useful for things like:
a) setting the canonical URL from the news detail page
b) setting the page title from a news detail page
or any other header variable that you want to set.

Hope this solves the issue once and for all.

Re: question about {eval var=$...}

Posted: Wed Mar 31, 2010 12:50 pm
by nicmare
ouh, this is VERY interesting and it finally solved my problems, thanks calguy :)