Git Product home page Git Product logo

zend-expressive-platesrenderer's Introduction

Plates Integration for Expressive

Repository abandoned 2019-12-31

This repository has moved to mezzio/mezzio-platesrenderer.

Build Status Coverage Status

Provides integration with Plates for Expressive.

Installation

Install this library using composer:

$ composer require zendframework/zend-expressive-platesrenderer

We recommend using a dependency injection container, and typehint against container-interop. We can recommend the following implementations:

Documentation

See the Expressive Plates documentation.

zend-expressive-platesrenderer's People

Contributors

acelaya avatar ezimuel avatar geerteltink avatar harikt avatar hdimo avatar knoxzin1 avatar koopzington avatar michalbundyra avatar mwillbanks avatar ocramius avatar pine3ree avatar robopuff avatar weierophinney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zend-expressive-platesrenderer's Issues

Add context-specific escaper helpers

This component should include an extension with the following context-specific escaping mechanisms from zend-escaper:

  • escapeHtml()
  • escapeHtmlAttr()
  • escapeJs()
  • escapeCss()
  • escapeUrl()

Adding these would be a value-add for those using Plates with Expressive, and provide added security features for template authors.

Make UrlExtension optional

I have recently migrated two expressive projects from twig to plates, and in both of them I have faced the same problem.

The twigrenderer package includes a set of factories that register a twig extension enabling access to the UrlHelper and the ServerUrlHelper, from the helpers package, but only if both of them are registered in the container.

On the other hand, the platesrenderer package factories force you to register them, otherwise an exception is thrown.

I was not using them in those projects, and I have been forced to install the helpers package and register both services.

Would it make sense to make it optional as in the twigrenderer?

I could provide a PR if you are ok with this idea.

problem with Loading plates Engine extension

Hi,
I try to load some extensions to plates engine but it seems not possible because I can not get instance of plates engine .
I fixed that by adding

//Zend\Expressive\Plates\PlatesRenderer
//....
public function getTemplate(){
        if (null === $this->template) {
            $this->template = $this->createTemplate();
        }
        return $this->template;
    }

example of extension to be loaded

use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;

class ChangeCase implements ExtensionInterface
{
    public function register(Engine $engine)
    {
        $engine->registerFunction('case', [$this, 'getObject']);
    }

    public function getObject()
    {
        return $this;
    }

    public function upper($var)
    {
        return strtoupper($var);
    }

    public function lower($var)
    {
        return strtolower($var);
    }
}

for this configuration

//template.global.php
'templates' => [
        'extension'         => 'phtml',
        'paths'             => [
            'app'    => ['templates/app'],
            'layout' => ['templates/layout'],
            'error'  => ['templates/error'],
            'user'   => ['templates/user'],
        ],
        'plates_extensions' => [
            Common\PlatesExtension\ChangeCase::class,
        ],
    ],

with this factory

use Interop\Container\ContainerInterface;
use Zend\Expressive\Template\TemplateRendererInterface;

class LoadPlatesExtensionFactory
{

    public function __invoke(ContainerInterface $container)
    {

        $template = $container->get(TemplateRendererInterface::class);
        $config = $container->get('config') ? $container->get('config') : [];
        $platesExtensions = [];
        if (isset($config['templates']['plates_extensions'])) {            
                $platesExtensions = $config['templates']['plates_extensions'];            
        }
        return new LoadPlatesExtension($template, $platesExtensions);
    }

}

the loadExtension middleware

use League\Plates\Extension\ExtensionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Expressive\Template\TemplateRendererInterface;

class LoadPlatesExtension
{

    protected $platesEngine;
    protected $platesExtensions;

    public function __construct(TemplateRendererInterface $platesEngine, array $platesExtensions = [])
    {
        $this->platesEngine = $platesEngine;
        $this->platesExtensions = $platesExtensions;
    }

    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next  = null)
    {
        $this->_loadExtensions();
        return $next($request, $response);
    }

    private function _loadExtensions(){
        if(count($this->platesExtensions)>0){
            foreach($this->platesExtensions as $extenstion) {
                if($extenstion instanceof ExtensionInterface)
                    $this->platesEngine->loadExtension( new $extenstion() );
                    //after editing PlatesRenderer class it works
                   //$this->platesEngine->getTemplate()->loadExtension(new $extension());
                else
                    throw \Exception(sprintf("%s not implement %s", $extenstion, ExtensionInterface::class));
            }
        }
    }
}

is that another solution to get it works ?

Proposal to Enable Plates Asset Extension

Proposal to refactor PlatesRendererFactory to enable asset extension.

use League\Plates\Extension as PlatesExtension;

// Create the engine instance:
$engine = new PlatesEngine();

// Enable asset extension
$engine->loadExtension(new PlatesExtension\Asset($config['paths']['assets']));

This will allow plates-layout.phtml in zend-expressive-skeleton to reference assets similar to:

<img src="<?=$this->asset('zf-logo.png')?>" alt="Zend Expressive" />

Where the assets path is configured in templates.global as:

    'templates' => [
        'extension' => 'phtml',
        'paths' => [
            'assets' => 'public',
            'app'    => ['templates/app'],
            'layout' => ['templates/layout'],
            'error'  => ['templates/error'],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.