예제 #1
0
 public function testIncludeTagNoWith()
 {
     $template = new Template();
     $template->setFileSystem(new LiquidTestFileSystem());
     $template->parse("Outer-{% include 'inner' %}-Outer-{% include 'inner' other:'23' %}");
     $output = $template->render(array("inner" => "orig", "var" => array(1, 2, 3)));
     $this->assertEquals("Outer-Inner: orig-Outer-Inner: orig23", $output);
 }
예제 #2
0
 /**
  * Tests filtered value assignment
  */
 public function testAssignWithFilters()
 {
     $template = new Template();
     $template->parse('{% assign test = "hello" | upcase %}{{ test }}');
     $this->assertTrue($template->render() === 'HELLO');
     $template->parse('{% assign test = "hello" | upcase | downcase | capitalize %}{{ test }}');
     $this->assertTrue($template->render() === 'Hello');
     $template->parse('{% assign test = var1 | first | upcase %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'A');
     $template->parse('{% assign test = var1 | last | upcase %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'C');
     $template->parse('{% assign test = var1 | join %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a b c');
     $template->parse('{% assign test = var1 | join : "." %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a.b.c');
 }
예제 #3
0
 /**
  * @expectedException \Liquid\LiquidException
  */
 public function testInvalidSyntax()
 {
     $template = new Template();
     $template->parse("{% cycle %}");
 }
예제 #4
0
파일: View.php 프로젝트: pathum/mvctest
 public function processTemplate(Template $template)
 {
     $context = new SS_LiquidContext($this);
     return $template->getRoot()->render($context);
 }
예제 #5
0
 /**
  * @expectedException \Liquid\LiquidException
  */
 public function testForInvalidSyntax()
 {
     $template = new Template();
     $template->parse("{% for elem %}{% endfor %}");
 }
예제 #6
0
 /**
  * @expectedException \Liquid\LiquidException
  */
 public function testInvalidSyntax()
 {
     $template = new Template();
     $template->parse("{% capture %} hello");
 }
예제 #7
0
<?php

/**
 * This file is part of the Liquid package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package Liquid
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->addPsr4('Liquid\\', __DIR__ . '/../src/Liquid');
use Liquid\Liquid;
use Liquid\Template;
Liquid::set('INCLUDE_ALLOW_EXT', true);
$protectedPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR;
$liquid = new Template($protectedPath . 'templates' . DIRECTORY_SEPARATOR);
// Uncomment the following lines to enable cache
//$cache = array('cache' => 'file', 'cache_dir' => $protectedPath . 'cache' . DIRECTORY_SEPARATOR);
// or if you have APC installed
//$cache = array('cache' => 'apc');
//$liquid->setCache($cache);
$liquid->parse(file_get_contents($protectedPath . 'templates' . DIRECTORY_SEPARATOR . 'child.tpl'));
$assigns = array('document' => array('title' => 'This is php-liquid', 'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', 'copyright' => '&copy; Copyright 2014 Guz Alexander - All rights reserved.'));
echo $liquid->render($assigns);
예제 #8
0
<?php

/**
 * This file is part of the Liquid package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package Liquid
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->addPsr4('Liquid\\', __DIR__ . '/../src/Liquid');
use Liquid\Liquid;
use Liquid\Template;
Liquid::set('INCLUDE_SUFFIX', 'tpl');
Liquid::set('INCLUDE_PREFIX', '');
$liquid = new Template();
$liquid->parse('{{ hello }} {{ goback }}');
echo $liquid->render(array('hello' => 'hello world', 'goback' => '<a href=".">index</a>'));
예제 #9
0
 /**
  * Check for cached includes
  *
  * @return boolean
  */
 public function checkIncludes()
 {
     $cache = Template::getCache();
     if ($this->document->checkIncludes() == true) {
         return true;
     }
     $source = $this->fileSystem->readTemplateFile($this->templateName);
     if ($cache->exists(md5($source)) && $this->hash == md5($source)) {
         return false;
     }
     return true;
 }