Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

insert tag

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
mouzaia
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Tue Jun 10, 2003 4:03 pm    Post subject: insert tag Reply with quote

Hello All,

Not really new to smarty, as an user, but now trying to go further, I have a pb with the insert tag. I looked everywhere to find something but ...

In the documentation, I noticed I can call a function with an insert tag

For instance:
<img src={insert name="getImage" image=#$urlimage#}>

$urlimage had been defined above, with a $smarty->assign("urlimage", "urlimage");
Does not work, it seems $urlimage is already in the cache.
I noticed in the documentation, I can "pass $smarty in my function as a second parameters", I dont see how !

Some help ?

Thanks
Laughing
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Tue Jun 10, 2003 10:54 pm    Post subject: Reply with quote

Hi mozaia:

It looks like your syntax is a little bit off:

Quote:
<img src={insert name="getImage" image=#$urlimage#}>


#$urlimage# ?? Does that work? It LOOKS like you are trying to dynamically select a configuration field value, though I never tried that myself. Are you really trying to do this:

<img src={insert name="getImage" image=$urlimage}> ??

Quote:
I noticed in the documentation, I can "pass $smarty in my function as a second parameters", I dont see how !


I assume you mean in the API. Smarty provides prototypes for PHP functions that you can register allowing you to customize how Smarty works. Most of the functions accept &$Smarty as a parameter, allowing for a lot of flexibility in your custom functions. Do you have an example of what you are trying to do?

HTH
Back to top
View user's profile Send private message
mouzaia
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Wed Jun 11, 2003 3:46 pm    Post subject: Reply with quote

boots wrote:
#$urlimage# ?? Does that work? It LOOKS like you are trying to dynamically select a configuration field value, though I never tried that myself. Are you really trying to do this:

<img src={insert name="getImage" image=$urlimage}> ??

Hi boots,

Ok, I understand, #var# is only from var coming from configuration files. Yes, I am trying to use the second image=$urlimage
So I correct it in my script, but I still have pb.
I am trying to use the cache system, with a dynamic part in my page. That $urlimage is coming for a php above. It seems like, eventhough insert tag is done for that, that the variable $urlimage is a part of the cache, so, when it is modified, the cache does not consider it. If I use #urlimage#, it works like it should.

boots wrote:

Most of the functions accept &$Smarty as a parameter, allowing for a lot of flexibility in your custom functions

That is what I look for, and I dont understand how I pass it to the function. Anyway I notice I can use a "global $Smarty;" in my function, the I have access to it.

In fact, I am just trying to study smarty, I have a new development to do, and I want do use: smarty, xhtml and css files, a kind of training Rolling Eyes

Thanks for the help.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jun 11, 2003 4:05 pm    Post subject: Reply with quote

hello,

1. if you want to access a config-var dynamically you can do {$smarty.config.$urlimage} or in your case {insert name="getImage" image=$smarty.config.$urlimage}

(see: http://smarty.php.net/manual/en/language.variables.smarty.config.php )

2. your assumption is correct: the parameters to insert a cached, so that insert always receives the same on each call.

3. if you want to use template-vars dynamically inside an insert function you can do sth. like:

Code:

function smarty_insert_getImage($params, &$smarty) {
   $image = $smarty->get_template_vars('urlimage');
   /* $image is the currently assinged $urlimage now, not the one it was when the cached template was generated */
}

(see: http://smarty.php.net/manual/en/api.get.template.vars.php )

just a few $0.02 from me Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mouzaia
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Wed Jun 11, 2003 6:13 pm    Post subject: Reply with quote

messju wrote:

1. if you want to access a config-var dynamically you can do {$smarty.config.$urlimage} or in your case {insert name="getImage" image=$smarty.config.$urlimage}

(see: http://smarty.php.net/manual/en/language.variables.smarty.config.php )

I'm going to see this. Shocked

messju wrote:

2. your assumption is correct: the parameters to insert a cached, so that insert always receives the same on each call.


Ok then I'm going to check with the configuration files. Embarassed


messju wrote:

3. if you want to use template-vars dynamically inside an insert function you can do sth. like:

Code:

function smarty_insert_getImage($params, &$smarty) {
   $image = $smarty->get_template_vars('urlimage');
   /* $image is the currently assinged $urlimage now, not the one it was when the cached template was generated */
}

(see: http://smarty.php.net/manual/en/api.get.template.vars.php )


Beautiful, thanks for that one. Interesting. Idea
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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