jaem3l/template-bundle
Composer 安装命令:
composer require jaem3l/template-bundle
包简介
Provides an easy way to use twig templates in your controller.
README 文档
README
This bundle provides a single @Template annotation that can be used in favor of
SensioFrameworkExtraBundle's annotation with the same name.
How it works
You can see the DummyController inside tests/Annotation/TemplateTest.php as a reference. Twig is fully supported, which should make writing your templates easier.
Requirements
- PHP 7.1
- SensioFrameworkExtraBundle 5.1
- Twig 2.4
Installation
The bundle can be installed via Composer:
composer require jaem3l/template-bundle
When using this bundle inside a Symfony 4 application bootstrapped with Flex,
make sure you have installed the twig-bundle and set it up with its recipe, e.g.
by using composer req twig.
Usage examples for Route-annotation
<?php
namespace App\Controller;
use jæm3l\TemplateBundle\Annotation\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class HelloController
{
/**
* @Route("/hello1")
* @Template("Hello World")
*/
public function simpleHelloAction()
{
}
/**
* @Route("/hello2 ")
* @Template("Hello {{ name }}")
*/
public function advancedHelloAction()
{
return [
'name' => 'Santa Claus',
];
}
/**
* @Route("/twig")
* @Template("{{ 1 + 2 }}")
*/
public function simpleExpressionAction()
{
}
/**
* @Route("/advanced_hello ")
* @Template("
* {% extends 'base.html.twig' %}
*
* {% block body %}
* Hello {{ name }}!
* {% endblock %}
* ")
*/
public function advancedTemplateAction()
{
return [
'name' => 'Santa Claus',
];
}
}
Usage examples for TemplateController
In your routing you can now rely on this controller for directly rendering a provided template:
# SF3: app/config/routing.yml
# SF4: config/routes.yaml
hello_world:
path: /hello-world
controller: jæm3l\TemplateBundle\Controller\TemplateController::template
defaults:
template: 'Hello World!'
twig_expression:
path: /twig-expression
controller: jæm3l\TemplateBundle\Controller\TemplateController::template
defaults:
template: '{{ 1 + 2 }}'
advanced_template:
path: /advanced-template
controller: jæm3l\TemplateBundle\Controller\TemplateController
defaults:
template: |
{% extends 'base.html.twig' %}
{% block body %}
Hello World!
{% endblock %}
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-22