Cobby Posted April 19, 2008 Share Posted April 19, 2008 Hi, I have templates stored in a database that I want to render. At the moment I just generate a temporary file and write the contents of the database query to it, the display that temporary file. <?php $result = $db->query($sql); file_put_contents('temp.tpl', $result['content']); $smarty->display('temp.tpl'); ?> But I don't like doing this as it just seems so unecessary, instead I would rather be like: <?php $result = $db->query($sql); $smarty->render($result['content']); ?> Anyway to do that? Cheers, Cobby Link to comment https://forums.phpfreaks.com/topic/101822-render-a-string-instead-of-template-file-with-smarty/ Share on other sites More sharing options...
RichardRotterdam Posted April 19, 2008 Share Posted April 19, 2008 I assume these templates are files stored in some folder. Why not get all the files (whether that is from a database or folder) place them in an array and then do the random function Link to comment https://forums.phpfreaks.com/topic/101822-render-a-string-instead-of-template-file-with-smarty/#findComment-521567 Share on other sites More sharing options...
Cobby Posted April 21, 2008 Author Share Posted April 21, 2008 I figured it out, Smarty supports resource plugins, so I created a text one. Now I can just go: <?php $smarty->assign('aVar', 'World'); $tpl = 'Hello {$aVar}!'; $smarty->display("text:$tpl"); // Hello World! ?> Link to comment https://forums.phpfreaks.com/topic/101822-render-a-string-instead-of-template-file-with-smarty/#findComment-522661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.