Current location: Hot Scripts Forums » Programming Languages » PHP » Smarty Caching Database Templates


Smarty Caching Database Templates

Reply
  #1 (permalink)  
Old 12-28-06, 09:24 AM
jimmy_B jimmy_B is offline
New Member
 
Join Date: Dec 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question Smarty Caching Database Templates

Hi,

I have one query and I hope you people can solve it. Problem is related to Smarty Caching Database Templates..

Most popular web applications and forums like IPB (invision power board) and vbulletin now a days store there all templates to database in the form of template bits (means in small portions like login form in one table row, lost password form in second row and so on).

And through Admin panel if someone wants to edit then web applications offers only little part of the code to edit in a very clean way means only login form not rest part of the webpage. These type of web applications basically store there all templates in database & create it's cache in some directory and when someone view the forum or site they pick the cache data display it.

But they export/import all the database templates in XML format.

Now I want to know is there any good & detail tutorial through which I can know how to store especially smarty templates in database and then create it's cache in some dir and also export/import templates in XML format. Also be able to re create a particular portion cache when I modify the template in table.
Reply With Quote
  #2 (permalink)  
Old 12-30-06, 02:26 PM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
Smarty Templates

Jimmy,

Its not really clear what you are trying to do by storing smarty templates in a db. That defeats the purpose of using smarty. Smarty gives you lots of power with its own caching mechanism and lots of control over where and how the cache is stored and used. You do this by simply extending the smarty class to one of your own and setting the caching values and locations in your new class.

Its important to remember that a cached smarty template is live php code not pure html or xml like you get with some systems.

PHP Code:



class Page extends smarty
{
  
$this->template_dir MY_DIR 'templates';
  
$this->compile_dir MY_DIR 'templates_c';
  
$this->config_dir MY_DIR 'configs';
  
$this->cache_dir MY_DIR 'cache';
  
$this->caching 1;
}

// The call

$myPage = & new Page();

$myPage->assign('xmlSection',function_to_get_xml('content'));

$myPage->display('myXML.tpl'); 
If you want pieces of documents stored in XML then store that in a db and include it in your smarty template as a variable or use a section/sectionelse clause in the template to display it. Php should do a good job of parsing it.

If you want its also very easy to extend smarty with your own code. Perhaps creating a function based off of the foreach/forelse smarty function that does xsl transforms for sections of xml from your database would work great. That way you can store the xsl in the db and your xml or call the xml from an xml enabled database. Your smarty function would then take the xml handed to it and apply the transform.

PHP Code:



$page 
= & new Page();

$page->assign('xmlMenuOne',get_xml_menu('menuOne'));
$page->assign('menuOneXSL',get_xsl_menu('menuOne'));
$page->display('index.tpl'); 
In your template:

PHP Code:



{xmlxslsection transform=menuOneXSL xml=xmlMenuOne
If you do this correctly then that should be all their is to it. Remember to use properly formatted xml island syntax somewhere in the smarty function definition or allow it to be wrapped around the function in the template.

Best of luck!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Smarty templates for classifieds software rodion PHP 1 10-11-06 09:36 AM
Simple, searchable book database max fischer Script Requests 0 05-14-05 01:00 PM
eMailing Smarty Templates bilco105 PHP 3 01-01-05 11:56 AM
Variables from templates in the database dannyallen PHP 0 06-28-04 03:49 PM


All times are GMT -5. The time now is 05:51 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.