2017 © Pedro Peláez
 

symfony-bundle template-bundle

Provides an easy way to use twig templates in your controller.

image

jaem3l/template-bundle

Provides an easy way to use twig templates in your controller.

  • Sunday, February 4, 2018
  • by dbrumann
  • Repository
  • 4 Watchers
  • 4 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

jaem3l TemplateBundle for Symfony 4

SensioLabsInsight Build Status Maintainability Test Coverage, (*1)

This bundle provides a single @Template annotation that can be used in favor of SensioFrameworkExtraBundle's annotation with the same name., (*2)

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., (*3)

Requirements

  • PHP 7.1
  • SensioFrameworkExtraBundle 5.1
  • Twig 2.4

Installation

The bundle can be installed via Composer:, (*4)

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., (*5)

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:, (*6)

# 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 %}

The Versions

04/02 2018

dev-master

9999999-dev

Provides an easy way to use twig templates in your controller.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Brumann

04/02 2018

v1.1.0

1.1.0.0

Provides an easy way to use twig templates in your controller.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Brumann

22/12 2017

v1.0.1

1.0.1.0

Provides an easy way to use twig templates in your controller.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Brumann

22/12 2017

v1.0.0

1.0.0.0

Provides an easy way to use twig templates in your controller.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Brumann