PRO: API bikereg.com

API: https://www.bikereg.com/api/EventSearchDoc.aspx, Example: https://www.bikereg.com/api/search?region=Rocky%20Mountain

Local stored JSON: http://api.json-content-importer.com/extra/json/bikereg-search.json


Shortcode:

[jsoncontentimporterpro nameoftemplate="bikereg"]

twig-Template:

<ul>{% for me in MatchingEvents | slice(0,3) %}
<li><a href={{me.EventPermalink}} target=_blank>{{me.EventName}}</a>
{{me.EventCity}}, {{me.EventState}}, 
{% set dateofevent = me.EventDate | slice(6, 10) %}
{{dateofevent | date("d.m.Y H:i") }}</li>
{% endfor %}</ul>

In Action:

PRO: API workshopbutler.com

This pages shows you how simple you can loop through a JSON-feed.

API: https://www.workshopbutler.com
locally stored at http://api.json-content-importer.com/extra/json/workshopbutler/1.json

{% for item in _context %}
{{item.unique_name}}: rating: {{item.rating}}, countries: 
    {% for co in item.countries %}
        {{co}}<br>
    {% endfor %}
{% endfor %}

In Action:

char..maq: rating: 8.96999988556, countries: AU
danny: rating: 0, countries: AU
NZ
dtellu: rating: 0, countries: NZ
d.josey: rating: 0, countries: IE
: rating: , countries:

PRO: Basic JSON-/Twig-Usage with “_context” or “_parent”

API-Source: http://api.json-content-importer.com/extra/json/2.json

If your JSON starts with “[{” try this:


JCI-template:

_context<br>
_context.0.id: {{_context.0.id}}<br> 
_context : {{_context | json_encode }}<br>
{% for item in _context %}
item {{loop.inxes}}: {{item | json_encode}}<br>
{% endfor %}
<hr>
_parent<br>
_parent.0.id: {{_parent.0.id}}<br> 
{% for item in _parent %}
_parent : {{_parent | json_encode }}<br>
item {{loop.inxes}}: {{item | json_encode}}<br>
{% endfor %}

Shortcode:

[jsoncontentimporterpro nameoftemplate="contextparent"]

twig defines some Global Variables

  • _self: references the current template name;
  • _context: references the current context;
  • _charset: references the current charset.

_parent is almost the same as _context but:
note the differnce of _context and _parent loops

In Action:

_context
_context.0.id: 1696
_context : [{"id":1696,"title":"1Experiment Your Way Through Change","type":14},{"id":2696,"title":"2Experiment Your Way Through Change","type":24}]
item : {"id":1696,"title":"1Experiment Your Way Through Change","type":14}
item : {"id":2696,"title":"2Experiment Your Way Through Change","type":24}
item : [{"id":1696,"title":"1Experiment Your Way Through Change","type":14},{"id":2696,"title":"2Experiment Your Way Through Change","type":24}]

_parent
_parent.0.id:
_parent : [{"id":1696,"title":"1Experiment Your Way Through Change","type":14},{"id":2696,"title":"2Experiment Your Way Through Change","type":24}]
item : {"id":1696,"title":"1Experiment Your Way Through Change","type":14}
_parent : [{"id":1696,"title":"1Experiment Your Way Through Change","type":14},{"id":2696,"title":"2Experiment Your Way Through Change","type":24}]
item : {"id":2696,"title":"2Experiment Your Way Through Change","type":24}