one in one test
[email protected] (bertrand Gugger) Fri, 09 Jun 2006 21:20:34 +0200
| Newsgroups | php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
bonsoir,
I wanted some one in one test.
As talking in irc with pete morgan, he asked me to post it here.
It's just requiring the include path:
# pwd
/blah/www/public_html/smarty/test
# cat .htaccess
php_value include_path
/blah/www/smarty/cvs/smarty:/blah/www/public_html/smarty/test
# cat index.php
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
$tpl_source =
'<h1>{$title}</h1>
<h2>{assign var="moo" value="$a.`b.c.d`"} {$moo}</h2>
{$s|substr:0:10}
<br />
{$s|string_format:"%.10s"}
';
$title = 'Smarty tests';
$a = array('b.c.d' => 'booh');
$s = '123456789abcdef0';
function here_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
$tpl_source = $GLOBALS['tpl_source'];
return true;
}
function here_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
$tpl_timestamp = time();
return true;
}
function here_get_secure($tpl_name, &$smarty_obj)
{
return true;
}
function here_get_trusted($tpl_name, &$smarty_obj)
{
}
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
// register the resource name 'here'
$smarty->register_resource('here', array('here_get_template',
'here_get_timestamp',
'here_get_secure',
'here_get_trusted'));
$vars = '';
foreach (array('title', 'a', 's') as $name) {
$smarty->assign($name, $$name);
$vars .= '<br />' . $name . ' = ' .
htmlspecialchars(print_r($$name, true));}
$smarty->display('here:blah');
die(
'<hr />it was: <br />' .
htmlspecialchars($tpl_source) .
'<br /> with: <br />' .
$vars
);
?>
Regards
--
toggg