hdytsgt/twigson-bundle

Symfony 3 Bundle for Twig Filter Extension to read JSON file or through URL

dev-master / 1.0.x-dev 2016-08-03 01:27 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:45:24 UTC


README

Symfony Bundle for Twig Filter Extension to read local JSON file or directly through URL.

Installation

Make sure you have installed Composer globally in your system. Then go to your terminal, inside your Symfony project run following command :

composer require hdytsgt/twigson-bundle:dev-master

When composer done installing the bundle, go to your app/AppKernel.php and add following Class new hdytsgt\TwigsonBundle\TwigsonBundle() into registerBundles() , example :

public function registerBundles()
{
        $bundles = [
            ...
            new hdytsgt\TwigsonBundle\TwigsonBundle(),
        ];
}

Usage

  1. Using local JSON file :

    {% set json = './countries.json' | twigson %}
    
    {% for key, item in json %}
    
       {{ key }} : {{ item }}
       
    {% endfor %}

    This will find countries.json under your Symfony web folder. And of course you can pass absolute path too.

  2. Using URL :

    {% set json = 'http://yoursite.com/countries.json' | twigson %}
    
    {% for key, item in json %}
    
       {{ key }} : {{ item }}
       
    {% endfor %}

Related Project

Twigson for Craft CMS

License

MIT