mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update docs for fetching only timestamp with custom template source functions
This commit is contained in:
@@ -1225,7 +1225,7 @@ function _run_mod_handler()
|
|||||||
{
|
{
|
||||||
$results = $this->_read_file($cache_file);
|
$results = $this->_read_file($cache_file);
|
||||||
|
|
||||||
// get the templates involved with this cache from the first line
|
// get the files involved with this cache from the first line
|
||||||
$contents = explode("\n", $results, 2);
|
$contents = explode("\n", $results, 2);
|
||||||
|
|
||||||
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||||
|
37
docs.sgml
37
docs.sgml
@@ -1382,14 +1382,19 @@ $smarty->display("file:/path/to/my/templates/menu.tpl");
|
|||||||
<sect2>
|
<sect2>
|
||||||
<title>Templates from a function call</title>
|
<title>Templates from a function call</title>
|
||||||
<para>
|
<para>
|
||||||
You can get templates from a custom function call, such as
|
You can get templates from a custom function call, such as
|
||||||
retrieving templates from a database. You do this by first
|
retrieving templates from a database. You do this by first
|
||||||
registering your resource handler function, then creating your
|
registering your resource handler function, then creating your
|
||||||
function to get the template. Smarty expects your function to be of
|
function to get the template. Smarty expects your function to be of
|
||||||
this form: funcname($tpl_name,&$tpl_source, &$tpl_timestamp)
|
this form: funcname($tpl_name,&$tpl_source,
|
||||||
{} $tpl_name is passed into the function, and your function should
|
&$tpl_timestamp[, boolean]) {} $tpl_name is passed into the
|
||||||
populate $tpl_source and $tpl_timestamp with the template source
|
function, and your function should populate $tpl_source and
|
||||||
and the last modified time of the template respectively.
|
$tpl_timestamp with the template source and the last modified time
|
||||||
|
of the template respectively. The fourth parameter is a boolean
|
||||||
|
value, used for determining if the source should be returned or
|
||||||
|
not. Default this value to true in your function. If false gets
|
||||||
|
passed, you only need to return the timestamp parameter. This was
|
||||||
|
added to Smarty 1.4.6.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
|
||||||
@@ -1399,12 +1404,18 @@ $smarty->display("file:/path/to/my/templates/menu.tpl");
|
|||||||
// from PHP script
|
// from PHP script
|
||||||
|
|
||||||
// put this function somewhere in your application
|
// put this function somewhere in your application
|
||||||
function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp) {
|
function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp,
|
||||||
// do database calls (or whatever) here to fetch your template, populating
|
$get_source=true) {
|
||||||
// $tpl_source and $tpl_timestamp.
|
|
||||||
|
|
||||||
$tpl_source = "This is a simulation of a template fetched from a db.";
|
if($get_source) {
|
||||||
$tpl_timestamp = mktime();
|
// do database calls (or whatever) here to fetch your template, populating
|
||||||
|
// $tpl_source and $tpl_timestamp.
|
||||||
|
$tpl_source = "This is a simulation of a template fetched from a db.";
|
||||||
|
$tpl_timestamp = mktime();
|
||||||
|
} else {
|
||||||
|
// just populate $tpl_timestamp.
|
||||||
|
$tpl_timestamp = mktime();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -1225,7 +1225,7 @@ function _run_mod_handler()
|
|||||||
{
|
{
|
||||||
$results = $this->_read_file($cache_file);
|
$results = $this->_read_file($cache_file);
|
||||||
|
|
||||||
// get the templates involved with this cache from the first line
|
// get the files involved with this cache from the first line
|
||||||
$contents = explode("\n", $results, 2);
|
$contents = explode("\n", $results, 2);
|
||||||
|
|
||||||
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||||
|
Reference in New Issue
Block a user