|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Mon Aug 23, 2004 12:01 pm Post subject: How to use templates stored as string? |
|
|
I am new to Smarty (its cool to develop websites with smarty!)
the templates are stored on the database and not as a file on the webserver.
How can I use this template?
Code: |
$result = $smarty->fetch(???string???); |
thank you for your help!!! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Mon Aug 23, 2004 2:17 pm Post subject: |
|
|
Thank you!
But I get this error after impleming own sql query:
Quote: | Warning: Smarty error: unable to read resource: "db:mainSite" in ... on line 1083 |
My code:
[php:1:bad57e4fa1]<?php
include("db_inc.php");
// put these function somewhere in your application
function db_get_template($tpl_name, &$tpl_source, &$smarty_obj)
{
global $db;
$sql = "select tmpcontent from tbl_template where tmpname='$tpl_name'";
$res = mysql_query($sql, $db);
if(mysql_num_rows($res))
{
$data = mysql_fetch_array($res);
$tpl_source = $data['tmpcontent'];
return true;
}
else
{
return false;
}
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
$tpl_timestamp = NULL;
}
function db_get_secure($tpl_name, &$smarty_obj)
{
return true;
}
function db_get_trusted($tpl_name, &$smarty_obj)
{
// null
}
define('SMARTY_DIR','/srv/www/htdocs/Smarty/');
require(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;
$smarty->register_resource("db", array("db_get_template",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));
$smarty->template_dir = '/srv/www/htdocs/test/';
$smarty->compile_dir = '/srv/www/htdocs/test/';
$smarty->assign('name','Bob');
$content = $smarty->fetch("db:mainSite");
echo "Result:";
echo $content;
?>[/php:1:bad57e4fa1] |
|
Back to top |
|
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Mon Aug 23, 2004 2:22 pm Post subject: |
|
|
Oh yeah! No help anymore please!
Here the solution:
[php:1:91d68bc897]<?php
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
return true;
}
?>[/php:1:91d68bc897]
Thank you ... |
|
Back to top |
|
|
|
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
|