|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sriramchitta Smarty Rookie
Joined: 14 Oct 2004 Posts: 14 Location: Hyderabad
|
Posted: Mon Nov 22, 2004 12:48 pm Post subject: problem accessing smarty variable inside {php}{/php} |
|
|
i am encoding the URL using base64_encode function of php
the code is like this in smarty template
{section name=index loop=$newsid}
<a href="index.php?qs={php} base64_encode('act=2&op=new&id={$newsid[index]->newsid})'> New </a>
{/section}
and the framework i use will decode this encode value in qs and redirects to the page requested but the problem here is that the {$newsid[index]->newsid} doesn't insert a value, instead it inserts {$newsid[index]->newsid} as plain text ({$newsid[index]->newsid}).
but i need this value to run my program successfully .... can anybody help me.
Sriram. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Nov 22, 2004 3:20 pm Post subject: |
|
|
Try using your php function as a modifier (btw: your code didn't include an /php so I am guessing):
Code: | {section name=index loop=$newsid}
<a href="index.php?qs={"act=2&op=new&id="|cat:$newsid[index]->newsid|base64_encode}> New </a>
{/section} |
It is always better to use a plugin or modifier than to drop into PHP in your template. Still, if you'd rather, you should be aware that Smarty code is ignored in {php} blocks. If you need to do something like retrieve a value, use the API function. eg:
Code: | {section name=index loop=$newsid}
{assign var=index value=$smarty.section.index.index}
<a href="index.php?qs=
{php}
$newsid = $this->get_template_vars('newsid');
$index = $this->get_template_vars('index');
echo base64_encode("act=2&op=new&id={$newsid[$index]->newsid}");
{/php}
> New </a>
{/section} |
or perhaps more simply,
Code: | {section name=index loop=$newsid}
{assign var=sendvalue value=$newsid[index]}
<a href="index.php?qs=
{php}
$index = $this->get_template_vars('sendvalue');
echo base64_encode("act=2&op=new&id={$sendvalue->newsid}");
{/php}
> New </a>
{/section} |
|
|
Back to top |
|
sriramchitta Smarty Rookie
Joined: 14 Oct 2004 Posts: 14 Location: Hyderabad
|
Posted: Mon Nov 22, 2004 5:09 pm Post subject: thank you |
|
|
hello boots,
Thanks for the reply. your reply solved my problem.
Thanks once again
Sriram |
|
Back to top |
|
|
|
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
|