2017 © Pedro PelĂĄez
 

symfony-bundle twigstring-bundle

Renders strings instead of files with Twig

image

zeliard91/twigstring-bundle

Renders strings instead of files with Twig

  • Thursday, November 2, 2017
  • by zeliard91
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,819 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 17 Forks
  • 0 Open issues
  • 3 Versions
  • 15 % Grown

The README.md

TwigstringBundle information & howto

Build Status, (*1)

This Symfony2 Bundle adds the possibility to render strings instead of files with the Symfony2 native Twig templating engine. The Bundle adds an additional service named twigstring. It is used the same way as the original templating service. The only difference is that the first argument of the method render(<string>, [<array]) is a string to parse instead of a template file., (*2)

The bundles supports variable output, conditions, loops and rendering of an controller. It does NOT support including templates, yet. It would interpret the template name as twigstring., (*3)

One example usage scenario is to load templates from the database instead of using files., (*4)

Extension ideas:, (*5)

  • option to include templates
  • add a black-/whitelist for allowed allowed twig tags

Installation

1. Register the bundle in composer

You need to add it to your composer.json requirements: ``` js { "require": { "zeliard91/twigstring-bundle": "~1.0" } }, (*6)


### 2. Downloading the bundle from packagist Install it by running the following command: $ ./composer.phar update zeliard91/twigstring-bundle ### 3. Registering the bundle in the kernel ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new LK\TwigstringBundle\LKTwigstringBundle(), // ... ); }

4. Registering the bundle in the configuration

``` yaml, (*7)

app/config/config.yml

lk_twigstring: # Decide if you want that all registered twig extensions must be loaded load_twig_extensions: true # (default to true), (*8)


### 5. Add additional extensions you are in need of (optional) ``` yaml # app/config/services.yml services: twigstring.extension.foo: class: Foo\BarBundle\Twig\FooBarExtension tags: - { name: twigstring.extension }

For a list of available extensions see fabpot/Twig-extensions or create one on your own with Symfony Cookbook and twig doc., (*9)

Usage

``` php // set example parameter $vars = array('var'=>'x');, (*10)

// get twigstring service $tpl_engine = $this->get('twigstring');, (*11)

// render example string $vars['test'] = 'u ' . $tpl_engine->render('v {{ var }} {% if var is defined %} y {% endif %} z{% for i in 1..5 %} {{ i }}{% endfor %}', $vars);, (*12)


or use the short way: ``` php // set example parameter $vars = array('var'=>'x'); // render example string $vars['test'] = 'u ' . $this->get('twigstring')->render('v {{ var }} {% if var is defined %} y {% endif %} z{% for i in 1..5 %} {{ i }}{% endfor %}', $vars);

Example output:

u v x y z

License

The bundle is licensed under MIT license. For full license see LICENSE file, (*13)

Authors

LarsK (Lars KrĂŒger), cordoval (Luis Cordova), r1pp3rj4ck (Attila Bukor), zeliard91 (Damien Matabon), (*14)

The Versions

02/11 2017

dev-master

9999999-dev https://github.com/zeliard91/TwigstringBundle

Renders strings instead of files with Twig

  Sources   Download

MIT

The Requires

 

The Development Requires

by zeliard91 / Damien Matabon

bundle string twig string twing

02/11 2017

v1.1.0

1.1.0.0 https://github.com/zeliard91/TwigstringBundle

Renders strings instead of files with Twig

  Sources   Download

MIT

The Requires

 

The Development Requires

by zeliard91 / Damien Matabon

bundle string twig string twing

29/01 2016

v1.0.0

1.0.0.0 https://github.com/zeliard91/TwigstringBundle

Renders strings instead of files with Twig

  Sources   Download

MIT

The Requires

 

The Development Requires

by zeliard91 / Damien Matabon

bundle string twig string twing