Skip to content

Instantly share code, notes, and snippets.

@graste
Created July 28, 2013 13:42
Show Gist options
  • Select an option

  • Save graste/6098625 to your computer and use it in GitHub Desktop.

Select an option

Save graste/6098625 to your computer and use it in GitHub Desktop.
twig multiline nested indentation question
require_once './lib/Twig/Autoloader.php';
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem('./');
$twig = new Twig_Environment($loader, array(
    'cache' => false,
));
$data = array(
        'name' => 'trololo',
        'asdf' => array(
            'nested' => 'value',
            'and' => array(
                'another' => 'deeply',
                'nested' => 'structure'
            )
        ),
        'foo' => 'bar'
    );
$bindings = array(
        'test' => $data,
        'data' => var_export($data, true)
    );
$template = $twig->loadTemplate('options.twig');
//$string = $template->render($bindings);
$template->display($bindings);

options.twig:

            {{ data | raw }}

gives:

            array (
  'name' => 'trololo',
  'asdf' => 
  array (
    'nested' => 'value',
    'and' => 
    array (
      'another' => 'deeply',
      'nested' => 'structure',
    ),
  ),
  'foo' => 'bar',
)

instead of what I need:

            array (
                'name' => 'trololo',
                'asdf' => 
                array (
                    'nested' => 'value',
                    'and' => 
                    array (
                        'another' => 'deeply',
                        'nested' => 'structure',
                    ),
               ),
               'foo' => 'bar',
            )

Or on a sidenote: How to do recursive indentation with blocks or macros or loops?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment