Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaem3l/templatebundle
Provides an easy way to use twig templates in your controller.
https://github.com/jaem3l/templatebundle
annotations symfony-bundle templating twig
Last synced: 2 months ago
JSON representation
Provides an easy way to use twig templates in your controller.
- Host: GitHub
- URL: https://github.com/jaem3l/templatebundle
- Owner: jaem3l
- Created: 2017-12-22T13:22:25.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-18T13:34:49.000Z (almost 6 years ago)
- Last Synced: 2024-10-30T10:09:59.479Z (2 months ago)
- Topics: annotations, symfony-bundle, templating, twig
- Language: PHP
- Size: 31.3 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jaem3l TemplateBundle for Symfony 4
===================================[![SensioLabsInsight](https://insight.sensiolabs.com/projects/77bafc12-418f-4148-8b94-12960475e6f5/mini.png)](https://insight.sensiolabs.com/projects/77bafc12-418f-4148-8b94-12960475e6f5)
[![Build Status](https://travis-ci.org/jaem3l/TemplateBundle.svg?branch=master)](https://travis-ci.org/jaem3l/TemplateBundle)
[![Maintainability](https://api.codeclimate.com/v1/badges/d5f218c9745a017417b5/maintainability)](https://codeclimate.com/github/jaem3l/TemplateBundle/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/d5f218c9745a017417b5/test_coverage)](https://codeclimate.com/github/jaem3l/TemplateBundle/test_coverage)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
-----------------------------------'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.yamlhello_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 %}
```