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

Accessing array template vars smartly in plugin?

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
gnudiff
Smarty n00b


Joined: 11 May 2004
Posts: 2

PostPosted: Tue May 11, 2004 12:09 pm    Post subject: Accessing array template vars smartly in plugin? Reply with quote

When you pass an array to smarty via assign(), it understands the "." notation, namely:

[php:1:b53d6a3681]<?php
$smarty->assign( 'foo', array( 'bar' => 1, 'gazonk' => 2));
?>[/php:1:b53d6a3681]

and you can refer to it from template by:

Code:
<input type="text" name="foo.bar"  value="{$foo.bar}">

will output: <input ... value="1"> into resulting HTML page.

Now, if I write a plugin, and I want to access foo.bar from within plugin func, it seems I can't use:

[php:1:b53d6a3681]<?php

function smarty_function_myfunc($params, &$smarty)
{
...
$smarty->get_template_vars('foo.bar'); // gives NULL
}

instead I have to use:

$smarty->get_template_vars('foo'); //gives array

?>[/php:1:b53d6a3681]

And do my own processing on the array. That is rather dumb -- can I have get the value of "foo.bar" directly somehow using the existing smarty parsing?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue May 11, 2004 1:21 pm    Post subject: Re: Accessing array template vars smartly in plugin? Reply with quote

gnudiff wrote:
That is rather dumb -- can I have get the value of "foo.bar" directly somehow using the existing smarty parsing?


no.

why don't you just pass $foo.bar as an attribute's value to the plugin?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gnudiff
Smarty n00b


Joined: 11 May 2004
Posts: 2

PostPosted: Tue May 11, 2004 1:40 pm    Post subject: Re: Accessing array template vars smartly in plugin? Reply with quote

messju wrote:

why don't you just pass $foo.bar as an attribute's value to the plugin?


because what i want to do is something like:


{checkbox name="foo.bar" }

so i don't have to write:

<input type="checkbox" name="foo.bar" {if $foo.bar=='Y' }checked{/if} >
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins 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