A Craft CMS Twig Extension for reading local JSON file or directly through URL.
-
Download ZIP and unzip file then place the
twigson
directory into yourcraft/plugins
directory. -
Install the plugin through Control Panel under
Settings > Plugins
-
Using local JSON file :
{% set json = './countries.json' | twigson %} {% for key, item in json %} {{ key }} : {{ item }} {% endfor %}
This will find
countries.json
under your Craft root folder. And of course you can pass absolute path too.
-
Using URL :
{% set json = 'http://yoursite.com/countries.json' | twigson %} {% for key, item in json %} {{ key }} : {{ item }} {% endfor %}