locaine/lcn-template-block-bundle

从 PHP/Twig 中填充模板代码块,稍后输出到 Twig 模板

安装: 252

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.1 2015-02-09 13:03 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:29:29 UTC


README

步骤 1: 下载包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ composer require locaine/lcn-template-block-bundle "~1.0"

此命令需要您全局安装了 Composer,具体请参考 Composer 文档中的 安装章节

步骤 2: 启用包

然后,在您的项目的 app/AppKernel.php 文件中添加以下行以启用此包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Lcn\TemplateBlockBundle\LcnTemplateBlockBundle(),
        );

        // ...
    }

    // ...
}

使用方法

PHP

示例控制器代码

//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

示例 Twig 模板代码

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