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

Assigned variables not compiled

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


Joined: 14 Aug 2006
Posts: 8

PostPosted: Tue Aug 15, 2006 7:20 am    Post subject: Assigned variables not compiled Reply with quote

Hi all

I've got a question:
I would like to do this:
$smarty->assign("mavariable","test");
$smarty->assign("variable_test","{$mavariable}");

And i would like that {$mavariable} is replace by test
i've tried with prefilter, modificator,... but noway.

The problem is that i want to receve a row in my db like :
This is my text [name], ...
i will change de [name] to {$name_var} but this var must be executed (replace by smarty)

How i can do that?

Thanks a lot.
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Aug 15, 2006 7:45 am    Post subject: Reply with quote

why do you all ask the same questions?
ask new questions or read the other posts.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
comicway
Smarty Rookie


Joined: 14 Aug 2006
Posts: 8

PostPosted: Tue Aug 15, 2006 7:54 am    Post subject: Reply with quote

I've read yesterday a lot of topic and try to search with the words (assigned var,...)
but i've didn't find.

Can you help me?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Aug 15, 2006 8:12 am    Post subject: Reply with quote

http://www.phpinsider.com/smarty-forum/search.php?search_keywords=eval%20resource&search_terms=all
Back to top
View user's profile Send private message Send e-mail Visit poster's website
comicway
Smarty Rookie


Joined: 14 Aug 2006
Posts: 8

PostPosted: Tue Aug 15, 2006 8:33 am    Post subject: Reply with quote

Ok i've reed that ressource is great but in my code i've got this:

$smarty->assign("info",$info);
// info: Hello {$name}{if $mr eq '1'}Connect{if}

$smarty->display('test.tpl');

and in my test.tpl:
<html>
<body>
{$info}
</body>
</html>

I didn't want to get a template from DB or other i've just want to like a prefilter that php replace {$info} by Hello {$name}{if $mr eq '1'}Connect{if}
and smarty execute this.

I think it is not possible with resources or i've didn't understant right

Thanks for your help

cris
Back to top
View user's profile Send private message
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Tue Aug 15, 2006 9:34 am    Post subject: Reply with quote

You need a prefilter? Then isn't it is the best you write a prefilter that fits your special needs?
http://smarty.php.net/manual/en/advanced.features.prefilters.php
Back to top
View user's profile Send private message
comicway
Smarty Rookie


Joined: 14 Aug 2006
Posts: 8

PostPosted: Tue Aug 15, 2006 9:41 am    Post subject: Reply with quote

I've tried this prefilter:
Code:

$smarty->assign("test","[bb]test[/bb]");

function change_code($tpl_source, &$smarty)
{
   return preg_replace("/(?<!\\\\)\[bb(?::\w+)?\](.*?)\[\/bb(?::\w+)?\]/si",'{$info.id}',$tpl_source);
}
   

$smarty->register_prefilter('change_code');

$smarty->display('info.tpl');


but the assign is do after the prefilter and theres no change i've got this:
[bb]test[/bb] and no 15 (the id of info)
Back to top
View user's profile Send private message
comicway
Smarty Rookie


Joined: 14 Aug 2006
Posts: 8

PostPosted: Wed Aug 16, 2006 11:41 am    Post subject: Reply with quote

Nobody?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Aug 16, 2006 1:31 pm    Post subject: Reply with quote

Did you not try eval?

http://smarty.php.net/manual/en/language.function.eval.php
Back to top
View user's profile Send private message Visit poster's website
comicway
Smarty Rookie


Joined: 14 Aug 2006
Posts: 8

PostPosted: Wed Aug 16, 2006 1:54 pm    Post subject: Reply with quote

No, i'will try it smell good...
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 -> General 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