2017 © Pedro PelĂĄez
 

library theme-twig-extension

Twig Extension for Theme

image

dflydev/theme-twig-extension

Twig Extension for Theme

  • Tuesday, January 15, 2013
  • by simensen
  • Repository
  • 1 Watchers
  • 1 Stars
  • 21 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Theme Twig Extension

A Theme extension for Twig., (*1)

Installation

Through Composer as dflydev/theme-twig-extension., (*2)

Usage

The following examples use the Symfony Routing implementation of ResourceUrlGeneratorInterface., (*3)

<?php
use Dflydev\Theme\ResourceUrlGenerator\SymfonyRoutingResourceUrlGenerator;
use Dflydev\Twig\Extension\Theme\ThemeTwigExtension;

// Assumes $themeProvider, $pathMapper, $urlGenerator, and $twig
// are already created and ready to be used.

$resourceUrlGenerator = new SymfonyRoutingResourceUrlGenerator(
    $themeProvider,
    $pathMapper,
    $urlGenerator
);

$themeTwigExtension = new ThemeTwigExtension(
    $resourceUrlGenerator
);

$twig->addExtension($themeTwigExtension);

Once enabled, Theme resources can be referenced by:, (*4)

{{ theme_resource('css/main.css') }}

If css/main.css is accessible directly via the Theme instances docroot (as determined by the PathMapperInterface) then a URL to the public resource will be used., (*5)

If css/main.css is not accessible directly, the UrlGeneratorInterface implementation will be used to generate a URL to the embedded Theme controllers., (*6)

All implementations of ResourceUrlGeneratorInterface should follow the pattern of:, (*7)

  1. Checking to see if the resource is available publicly and using that if available.
  2. Generating a fallback URL to expose non-public resources.

Controller Requirements Example (Silex + Symfony Routing)

  • _dflydev_typed_theme_handler: Expects three params, type, name, and the resource. Name can be changed by calling setTypedRouteName()., (*8)

    Example:, (*9)

    <?php
    $app->get('/_theme_typed/{type}/{name}/resources/{resource}', function($type, $name, $resource) use ($app)  {
       // do something to handle the theme request and return the
       // contents of the theme resource manually.
    })
    ->assert('name', '.+')
    ->assert('resource', '.+')
    ->bind('_dflydev_typed_theme_handler');
    
  • _dflydev_theme_handler: Expects two params, name and the resource. Name can be changed by calling setTypedRouteName()., (*10)

    Example:, (*11)

    <?php
    $app->get('/_theme/{name}/resources/{resource}', function($name, $resource) use ($app) {
       // do something to handle the theme request and return the
       // contents of the theme resource manually.
    })
    ->assert('name', '.+')
    ->assert('resource', '.+')
    ->bind('_dflydev_theme_handler');
    

License

MIT, see LICENSE., (*12)

Community

If you have questions or want to help out, join us in the [#dflydev, 1] channel on irc.freenode.net., (*13)

  1. irc://irc.freenode.net/#dflydev ↩, (*14)

The Versions

15/01 2013

dev-master

9999999-dev

Twig Extension for Theme

  Sources   Download

MIT

The Requires

 

twig extension theme