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

assign value using assign();

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
jovenshadow11
Smarty Rookie


Joined: 28 Jun 2011
Posts: 14

PostPosted: Thu Jul 14, 2011 1:17 pm    Post subject: assign value using assign(); Reply with quote

i have a template that has {$content} the data that i will put in the {$content} will be pulled out from the database

$dataFromDBase = "this is a sample datafrom DBase and another {$newVariable}";
$smarty->assign('content',$dataFromDBase);


Knowing that i used "{$newVariable}" in my content, now i want to assign value to this variable so i add this

$smarty->assign('newVariable',"new data for newVariable");

but when i will display this is what show on the browser

this is a sample datafrom DBase and another {$newVariable}

why the new data for {$newVariable} is not showing/ and its literally shows {$newVariable} ???

what is the right way to assign a value to a variable i put in my content?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 14, 2011 1:26 pm    Post subject: Reply with quote

In template use {eval ...}:

http://www.smarty.net/docs/en/language.function.eval.tpl

Or in PHP:

Code:
$var = $smarty->fetch("string:$content");
$smarty->assign('var',$var);
Back to top
View user's profile Send private message Visit poster's website
jovenshadow11
Smarty Rookie


Joined: 28 Jun 2011
Posts: 14

PostPosted: Thu Jul 14, 2011 1:44 pm    Post subject: Reply with quote

Thank you very much mohrt!

this is the new code and it works..

$smarty->assign('newTitle',"this is a test");

$var = $smarty->fetch("string:".$content->getContent()); // $content->getContent() is my class for getting the content in the database.

$smarty->assign('content',$var);

again thank you for your help!
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 -> Smarty 3 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