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

How to use templates stored as string?

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


Joined: 23 Aug 2004
Posts: 7

PostPosted: Mon Aug 23, 2004 12:01 pm    Post subject: How to use templates stored as string? Reply with quote

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
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Aug 23, 2004 1:49 pm    Post subject: Reply with quote

http://smarty.php.net/manual/en/templates.from.elsewhere.php
Back to top
View user's profile Send private message Visit poster's website
macfreakz
Smarty Rookie


Joined: 23 Aug 2004
Posts: 7

PostPosted: Mon Aug 23, 2004 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
macfreakz
Smarty Rookie


Joined: 23 Aug 2004
Posts: 7

PostPosted: Mon Aug 23, 2004 2:22 pm    Post subject: Reply with quote

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
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 -> Smarty Development 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