2017 © Pedro Peláez
 

symfony-bundle lcn-template-block-bundle

Populate blocks of template code from PHP/Twig and output them later in a Twig Template

image

locaine/lcn-template-block-bundle

Populate blocks of template code from PHP/Twig and output them later in a Twig Template

  • Monday, February 9, 2015
  • by jfmaeck
  • Repository
  • 2 Watchers
  • 0 Stars
  • 243 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

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') }}

The Versions

09/02 2015

dev-master

9999999-dev

Populate blocks of template code from PHP/Twig and output them later in a Twig Template

  Sources   Download

MIT

by Jonas Fischer-Maeck

twig symfony 2

09/02 2015

1.0.1

1.0.1.0

Populate blocks of template code from PHP/Twig and output them later in a Twig Template

  Sources   Download

MIT

by Jonas Fischer-Maeck

twig symfony 2

09/02 2015

1.0.0

1.0.0.0

Populate blocks of template code from PHP/Twig and output them later in a Twig Template

  Sources   Download

MIT

by Jonas Fischer-Maeck