Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:, (*1)
$ composer require locaine/lcn-template-block-bundle "~1.0"
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*2)
Step 2: Enable the Bundle
Then, enable the bundle by adding the following line in the app/AppKernel.php
file of your project:, (*3)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Lcn\TemplateBlockBundle\LcnTemplateBlockBundle(),
);
// ...
}
// ...
}
Usage
PHP
Example controller code:, (*4)
//add code to a block
$this->container->get('lcn.template_block')->add('BLOCK_NAME', 'BLOCK_CONTENT');
////adding the same code to a block again is ignored by default. You can force adding the same code by supplying false as third argument
$this->container->get('lcn.template_block')->add('BLOCK_NAME', 'BLOCK_CONTENT', false);
//you can set the code in a block effectively overriding existing code in the block
$this->container->get('lcn.template_block')->set('BLOCK_NAME', 'BLOCK_CONTENT');
//clear a block
$this->container->get('lcn.template_block')->clear('BLOCK_NAME');
//get the code of a block
$this->container->get('lcn.template_block')->get('BLOCK_NAME', 'OPTIONAL_FALLBACK_CODE');
TWIG
Example Twig template code:, (*5)
{# add code to a block #}
{{ lcn_add_to_template_block('BLOCK_NAME', 'BLOCK_CONTENT') }}
{# adding the same code to a block again is ignored by default. You can force adding the same code by supplying false as third argument #}
{{ lcn_add_to_template_block('BLOCK_NAME', 'BLOCK_CONTENT', false) }}
{# you can set the code in a block effectively overriding existing code in the block #}
{{ lcn_set_template_block('BLOCK_NAME', 'BLOCK_CONTENT') }}
{# clear a block #}
{{ lcn_clear_template_block('BLOCK_NAME') }}
{# get the code of a block #}
{{ lcn_template_block('BLOCK_NAME', 'OPTIONAL_FALLBACK_CODE') }}
{# the code is escaped by default, but cou can also get the raw code of a block #}
{{ lcn_template_block_raw('BLOCK_NAME', 'OPTIONAL_FALLBACK_CODE') }}