Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Parsing problem on a registered function

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
gianiaz
Smarty Rookie


Joined: 14 Dec 2006
Posts: 25
Location: Italy

PostPosted: Fri Dec 21, 2007 12:31 pm    Post subject: Parsing problem on a registered function Reply with quote

Hi, I'm going to change all my urls in my template to something that is better for Search engines, then I want to change a link in this form

Code:

http://www.mysite.com/index.php?action=test&id=1&name=Some name


to

Code:

http://www.mysite.com/test/1/some-name.html


For doing this I writed and registered a function that will change all my urls.

In my template I have something like this:
Code:

<a href="{$smarty.server.SCRIPT_NAME}?action=test&id={$object->id}&name={$object->name}>....</a>


My function take 1 parameter and returns the new url, but when I try it:

Code:

a href="{beatify_url url="$smarty.server.SCRIPT_NAME?action=test&id=$object->id&name=$object->name"}">...</a>


I got this error:

Quote:

Catchable fatal error: Object of class articolo could not be converted to string in D:\www\XXXX\smarty\pubblic\templates_c\%%FF^FFD^FFD4BB14%%viewart.tpl.php on line 134


It seems that the parser try to convert object before accessing to its property.

What's wrong on my code?

Thank you
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Dec 22, 2007 12:24 am    Post subject: Reply with quote

Yes, you are correct and the reason is due to a small mistake in your syntax. When you want Smarty to interpolate template vars in double quotes, you have to use backticks for everything except the most simple of template variable expressions.

http://smarty.php.net/manual/en/language.syntax.quotes.php

So basically, if you surround the template var references in backticks, you should be golden.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP