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);
 }
 /**
  * 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');
 }
Exemple #3
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);
Exemple #4
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>'));