GithubHelp home page GithubHelp logo

shinigamicorei7 / view Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 202 KB

Solución simple para poder usar twig (motor de plantillas para php) sin usar ningún tipo de framework o patrón de arquitectura de software.

License: Other

PHP 91.89% HTML 3.88% Makefile 4.23%

view's Introduction

ViewManager

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Join the chat at https://gitter.im/shinigamicorei7/view

Instalación y configuración

{
    "require" : {
        "shinigamicorei7/view" : "dev-master"
    }
}

Creamos un archivo de configuración:

<?php

return array(
    /**
     * Este campo es obligatorio ya que se usará como directorio root de las plantillas
     *
     * templates_dir string|array
     */
    'templates_dir' => array(
        'path/to/templates/'
    ),
    /**
     * Namespaces que se usaran en la aplicación Ej:
     *
     * echo view('@namespace/index.twig',$data);
     * o
     * echo View::render('@namespace/index.twig',$data);
     *
     * namespaces null|array
     */
    'namespaces' => array(
        'test' => 'path/to/test/views/'
    ),
    /**
     * Opciones diponibles
     *
     * @see \Twig_Environment
     * options array
     */
    'options' => array(
        'debug' => false,
        'cache' => 'path/to/cache/'
    )
);

Uso

require 'path/to/vendor/autoload.php';

View::setDirConfig('path/to/view/config.php');

/**
* Usando la sobrecarga de clases
*/
echo View::render('index.twig',array('nombre' => 'Shinigamicorei7'));


/**
* Usando la función de ayuda
* echo view('index.twig',array('nombre' => 'Shinigamicorei7'));
*/

/**
* Usando los namespaces definidos en nuestro archivo de configuración
* echo view('@test/index.twig',array('nombre' => 'Shinigamicorei7')); 
*/

ViewManager hereda todas las funciones de la clase Twig_Environment, así que tenemos todas las funciones brindadas por esta clase:

/**
* is_a es una función del core de php, por esa razón la invocamos con una cadena de texto
*/
$is_a = new Twig_SimpleFunction('is_a', 'is_a');

$filter = new Twig_SimpleFilter('array_filter', function ($context, $string) {
    //tu código
}, array('needs_context' => true));

$test = new Twig_SimpleTest('red', function ($value) {
    if (isset($value->color) && $value->color == 'red') {
        return true;
    }
    if (isset($value->paint) && $value->paint == 'red') {
        return true;
    }
    return false;
});

View::addFunction($is_a);

View::addFilter($filter);

View::addTest($test);

Licencia

La dependencia View es software de tipo OpenSource, usando la licencia MIT

view's People

Contributors

shinigamicorei7 avatar gitter-badger avatar

Watchers

 avatar Baku_Roku avatar

Forkers

gitter-badger

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.