Skip to content

Instantly share code, notes, and snippets.

@wkjagt
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save wkjagt/9368879 to your computer and use it in GitHub Desktop.

Select an option

Save wkjagt/9368879 to your computer and use it in GitHub Desktop.

Revisions

  1. wkjagt revised this gist Mar 5, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion twig-example.php
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    $twigEnv = new Twig_Environment($loader, $options);

    // adding extenstions to Twig.
    $twig->addExtension(new MyTwigExtension);
    $twigEnv->addExtension(new MyTwigExtension);

    // using the Twig Environment to render templates.
    $templateVars = array('foo' => 'bar');
  2. wkjagt revised this gist Mar 5, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions twig-example.php
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,14 @@

    // setup a template loader used by Twig to load the template strings. Most common is loading
    // templates from the file system. This loader needs takes a template path or an array of
    // template paths as argument to its constructor
    // template paths as argument to its constructor.
    $templatePath = __DIR__.'/templates';
    $loader = new Twig_Loader_Filesystem($templatePath);

    // setup the twig environment. This is used for the actual rendering. The Twig environment takes
    // the loader and an array of options as its arguments.
    // the loader and an array of options as its arguments. In this example I use the twig environment
    // directly but in the context of a framework it would be made available to the logic that uses it,
    // for example through a dependency injection container.
    $options = array(
    'cache' => __DIR__.'/template-cache',
    // other options here
  3. wkjagt created this gist Mar 5, 2014.
    22 changes: 22 additions & 0 deletions twig-example.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php

    // setup a template loader used by Twig to load the template strings. Most common is loading
    // templates from the file system. This loader needs takes a template path or an array of
    // template paths as argument to its constructor
    $templatePath = __DIR__.'/templates';
    $loader = new Twig_Loader_Filesystem($templatePath);

    // setup the twig environment. This is used for the actual rendering. The Twig environment takes
    // the loader and an array of options as its arguments.
    $options = array(
    'cache' => __DIR__.'/template-cache',
    // other options here
    );
    $twigEnv = new Twig_Environment($loader, $options);

    // adding extenstions to Twig.
    $twig->addExtension(new MyTwigExtension);

    // using the Twig Environment to render templates.
    $templateVars = array('foo' => 'bar');
    $html = $twigEnv->('a-template.html.twig', $templateVars);