示例#1
0
 function testRenderSectionNoCache()
 {
     $m = $this->m;
     $m->enableCache = false;
     $res = $m->renderTemplate("section1");
     $this->assertEqual($res, "\n");
     $res = $m->renderTemplate("section1", array("foo" => array("bla" => "bla")));
     $this->assertEqual($res, "bla\n");
     $res = $m->renderTemplate("section1", array("foo" => array(array("bla" => "1 "), array("bla" => "2 "), array("bla" => "3 "), array("bla" => "4 "), array("bla" => "5 "))));
     $this->assertEqual($res, "1 2 3 4 5 \n");
     /* test reloading cached stuff */
     $m = new Proust\Proust(array("templatePath" => dirname(__FILE__) . "/files/"));
     $res = $m->renderTemplate("section1");
     $this->assertEqual($res, "\n");
     $res = $m->renderTemplate("section1", array("foo" => array("bla" => "bla")));
     $this->assertEqual($res, "bla\n");
     $res = $m->renderTemplate("section1", array("foo" => array(array("bla" => "1 "), array("bla" => "2 "), array("bla" => "3 "), array("bla" => "4 "), array("bla" => "5 "))));
     $this->assertEqual($res, "1 2 3 4 5 \n");
 }
示例#2
0
<?php

/* example with partials, caching and some compiler options */
require_once dirname(__FILE__) . "/../Proust.php";
$p = new Proust\Proust(array("enableCache" => true, "cacheDir" => dirname(__FILE__) . "/.proust.cache/", "templatePath" => dirname(__FILE__) . "/templates/", "disableObjects" => "true", "compilerOptions" => array("disableLambdas" => true, "includePartialCode" => true)));
$data = array("foo" => array("x" => 1, "y" => 2, "z" => array(1, 2, 3, 4)));
echo $p->renderTemplate("section1", $data);
echo "\nIndentation disabled:\n";
$p->compilerOptions["disableIndentation"] = true;
echo $p->renderTemplate("section1", $data);
echo "\nWith explicit partials:\n";
$p->compilerOptions["disableIndentation"] = false;
$p->partials = array("partial2" => "{{foo.y}}");
echo $p->renderTemplate("section1", $data);
echo "\nShow caching in effect:\n";
$p->partials = array("partial2" => "NEW VERSION: {{foo.y}}");
echo $p->renderTemplate("section1", $data);
echo "\nAfter clearCache:\n";
$p->clearCache();
echo $p->renderTemplate("section1", $data);