A Craft CMS Twig Extension for reading local JSON file or directly through URL.
-
Download ZIP and unzip file then place the
twigsondirectory into yourcraft/pluginsdirectory. -
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.jsonunder 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 %}