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

Some question on Smarty and mysql.

 
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
AdamChan
Smarty n00b


Joined: 26 Jul 2003
Posts: 2

PostPosted: Sat Jul 26, 2003 10:49 am    Post subject: Some question on Smarty and mysql. Reply with quote

Can i save the templates at Mysql
and load it ?

$data = "<html><title>{$title}</title></html>";
$smarty->assign('title',"My website");
$smarty->display($data); <-- can i ?


can i do that ?
Thank
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Jul 26, 2003 1:38 pm    Post subject: Reply with quote

Not exactly what you posted but something close can be found using a custom resource handler. Look at http://smarty.php.net/manual/en/templates.from.elsewhere.php
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
AdamChan
Smarty n00b


Joined: 26 Jul 2003
Posts: 2

PostPosted: Sat Jul 26, 2003 3:52 pm    Post subject: Reply with quote

amm....
thanks .

i've look the page , but any other easyway to do that ?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Jul 28, 2003 8:31 am    Post subject: Re: Some question on Smarty and mysql. Reply with quote

you actually asked two questions:

question 1
Quote:
Can i save the templates at Mysql and load it ?


yes and aztek pointed you to what you really want.

ones you got a grasp on resources they are easy. you only have to supply two functions, 1 to obtain the content and 1 to obtain the modification-time of the template. the other two functions are not needed in normal operation and can return always "false". you can put the 4 functions in a file resource.[name].php in your plugins-dir, so they are auto-loaded on demand and you don't have to register your resource.
(so you can not forget to register it Smile )

the file simply has to contain
function smarty_resource_[name]_source(...
function smarty_resource_[name]_timestamp(...
function smarty_resource_[name]_secure(...
function smarty_resource_[name]_trusted(...
(but you only have to implement the former 2)

after that you can use you templates everywhere:
$smarty->display("[name]:$resource_name_maybe_the_mysql_record_id")
or
{include file="db:$id"}


question 2
Quote:
$data = "<html><title>{$title}</title></html>";
$smarty->assign('title',"My website");
$smarty->display($data); <-- can i ?


this can also be done with eval: http://smarty.php.net/manual/en/language.function.eval.php

but this would mean, you don't use the compiling-feature of smarty (if you don't employ caching, the template from the db is recompiled on every use), which would render the use of smarty pretty pointless.

eval might look easier at first sight but resources are much smarter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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