定制 r1pp3rj4ck/twigstringbundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

r1pp3rj4ck/twigstringbundle

Composer 安装命令:

composer require r1pp3rj4ck/twigstringbundle

包简介

Renders strings instead of files with Twig

关键字:

README 文档

README

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.

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.

One example usage scenario is to load templates from the database instead of using files.

Extension ideas:

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

Installation

If you are an advanced Symfony developer, you know how things are done. The package's name is r1pp3rj4ck/TwigstringBundle and you need the dev-master version of it, and the bundle's FQN is LK\TwigstringBundle\LKTwigstringBundle(). You also need a top-level entry to your config: lk_twigstring: ~.

Of course, if you're not sure about yourself, here is the step-by-step installation procedure:

1. Register the bundle in composer

You need to add it to your composer.json requirements:

{
    "require": {
         "r1pp3rj4ck/TwigstringBundle": "dev-master"
    }
}

2. Downloading the bundle from packagist

Install it by running the following command:

$ ./composer.phar update r1pp3rj4ck/TwigstringBundle

3. Registering the bundle in the kernel

<?php
// app/AppKernel.php

public function registerBundles() {
    $bundles = array(
        // ...
        new LK\TwigstringBundle\LKTwigstringBundle(),
        // ...
    );
}

4. Registering the bundle in the configuration

# app/config/config.yml
lk_twigstring: ~

Usage

// set example parameter
$vars = array('var'=>'x');

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

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

or use the short way:

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

Authors

LarsK (Lars Krüger), cordoval (Luis Cordova), r1pp3rj4ck (Attila Bukor)

统计信息

  • 总下载量: 14.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-03-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固