|
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 |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Sat Jan 16, 2010 7:49 pm Post subject: Why to throw {php}...{/php} tags away? |
|
|
A developer asked me a question that was reasonable due to confusions arose by using {php}...{/php} tags.
Here is a basic version of the question:
Quote: | My page contains a member listing section - which lists all members of the site, It also contains a edit and delete link corresponding to each member, So on clicking edit or delete what i need to do is go to another page where editing is done. For that I need to pass member id, And their the problem is I NEED TO PASS ENCRYPTED MEMBER ID , My code looks something like this,
<a href="edit.php?memid={php}echo
base64_encode($result[data].memid){/php}">edit</a>
But when i checked in edit.php decrypted the value i got it as "memid"
{$result[data].memid} - prints the correct value - in my members.tpl page |
I just want you (dear reader of this thread) to educate why you should NOT use {php}...{/php}. You can definitely do any complex sytem without these tags. Here was my answer.
Quote: | Here is the possible solution, replacement:
<a href="edit.php?memid={$result[data].memid|base64_encode}">edit</a>
This is yet, a short and straight forward solution.
Though base64_encode is a php's callable function, you can use it in the tpl, as I listed above.
When you jump off the {php} ... {/php} tags, Smarty loses its track to handle the variables. So the variable $result is NO LONGER AVAILABLE to the Smarty's TPL Parser. Hence, it can not give you the correct information, as it tries to understand that $result is genuinely a PHP variable, that you write in .php files. |
The basic problem is that as soon as you begin {php} tag, Smarty will enter into a state out of the parsing engine. And it becomes like your native php codes.
So, just assume that these tags do not exist, or learn them not to use.
Lot of thanks to the original poster, who gave me a chance to clarify this! |
|
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
|