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

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

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

Post 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!
Last edited by nicmare on Wed Mar 31, 2010 12:51 pm, edited 1 time in total.
Peciura

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

Post by Peciura »

{content block='Meta Description' oneline='true' assign="temp"}
{eval var=$temp  assign='metadesc'}

{* use it whereever you want *}
{$metadesc}
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

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

Post 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?!
Peciura

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

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

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

Post by nicmare »

ouh, this is VERY interesting and it finally solved my problems, thanks calguy :)
Post Reply

Return to “Modules/Add-Ons”