Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Variable from PHP and comiling problem.

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Sim00n
Smarty n00b


Joined: 01 Feb 2010
Posts: 3

PostPosted: Sat Jul 10, 2010 6:43 pm    Post subject: Variable from PHP and comiling problem. Reply with quote

Hi guys. I got problem with compiling of tpl file.
I'm creating "code's hosting" - something like google documents but for programmers to store their codes. Right now I'm reding content from file and assignig it to a variable to send it to tpl like that:
Code:

$smarty->assign("Code", $content);

and than in tpl:
Code:

<textarea class="field" style="width: 95%; height: 250px;" wrap="off" name="name" cols="90" rows="90"> {$Code} </textarea>

The problems stars when variable Codes contains some smarty parts like {$if} etc. so I tried to use {literal} functions to "turn off" this code in compiling but the output was "{$Code}" instead of the reall code that i want to show.

The question is how to make it work Smile

Regards, Sim00n.
Back to top
View user's profile Send private message
ChrisFah
Smarty Pro


Joined: 02 Nov 2009
Posts: 124
Location: Traun, Austria

PostPosted: Sat Jul 10, 2010 7:30 pm    Post subject: Reply with quote

Hi,

try this(not tested):

Before assigning it to a smarty var,

Code:
$content = '{literal}'.$content.'{/literal}';
$smarty->asign('Code', $content);


Code:
<textarea class="field" style="width: 95%; height: 250px;" wrap="off" name="name" cols="90" rows="90"> {$Code} </textarea>


Now, everything between {literal} shoult be untouched.

Regard, Chris
Back to top
View user's profile Send private message
douglassdavis
Smarty Elite


Joined: 21 Jan 2008
Posts: 263

PostPosted: Sat Jul 10, 2010 7:49 pm    Post subject: Re: Variable from PHP and comiling problem. Reply with quote

does {$Code|escape} work?

Just outputting a var containing smarty code shouldn't really be a problem, so I'm not sure exactly what the problem is otherwise.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sat Jul 10, 2010 10:45 pm    Post subject: Reply with quote

smarty template syntax in a variable should have no problems. it should not compile as a template unless you eval the variable. it should be treated as plain text?
_________________
Monte
http://www.phpinsider.com/
http://mohrt.blogspot.com/
Back to top
View user's profile Send private message Visit poster's website
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 345
Location: Kathmandu, Nepal

PostPosted: Tue Jul 13, 2010 8:38 pm    Post subject: Thats not true. Reply with quote

Few comments:
{$if} is NOT a part of Smarty related things.
You are confusing with {if}, or mistyped it.

Anything you put in $content should appear as {$Code}.
So, I guess, your PHP's value of $content is wrong.

Hence, appending {literal} tags are useless.
Just debug what is wrong with $content.
_________________
Project Manager and Senior Programmer (Bimal Poudel)
Smarty Framework - use it now
Sanjaal Corps, Organized freelancing provider

Hire me in oDesk immediately | Professional support | Personal URL
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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