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

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

If your JSON starts with “[{” try this (or see here if you add some more twig code):


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 difference 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}