api.snooker.org: Nested Shortcodes

Task: Display all players from http://api.snooker.org/?rt=MoneyRankings&s=2021 and get their names from the feed http://api.snooker.org/?p=PLAYERID


See how this works:

{% for i in _context | slice(0,5) %} 
{% if i.PlayerID > 0 %}
    Position: {{i.Position}} - <a href="http://api.snooker.org/?p={{i.PlayerID}}" target="_blank">PlayerID: {{i.PlayerID}}</a><br>
{% endif %} 
{% endfor %}

Use this Shortcode:

[jsoncontentimporterpro nameoftemplate="playerlist"] 

This gives you the list of the first 5 players (slice-filter) players and the PlayerID with a link to the JSON with more details. Now we need to grab this JSON-detaildata and add it to the ranking. For this we again ask the API with a JCI-Shortcode.

  • Add another JCI-Template:
    URL: leave blank
    Name: playerdetails
    twig-template:
{{ _context | json_encode  }}

Then alter the JCI-template playerlist:

{% for i in _context | slice(0,5) %} 
{% if i.PlayerID > 0 %}
    Position: {{i.Position}} - <a href="http://api.snooker.org/?p={{i.PlayerID}}" target="_blank">PlayerID: {{i.PlayerID}}</a><br>
{% endif %} 
{% endfor %}

And alter the Shortcode:

[jsoncontentimporterpro nameoftemplate="playerlist" orderofshortcodeeval=10]

orderofshortcodeeval=10 tells the plugin not to execute the Shotcode in the twig-code.

{% for i in _context | slice(0,5) %} 
{% if i.PlayerID > 0 %}
    {% set sc = '[jsoncontentimporterpro nameoftemplate="playerdetails" url="http://api.snooker.org/?p='~i.PlayerID~'"]' %}
    {% set scexec = (sc | doshortcode ) %}
    {% set playerdetails = (scexec | json_decode(TRUE)  ) %}
    <img src="{{playerdetails.0.Photo}}"><br clear="all">{{i.Position}}. <a href="http://api.snooker.org/?p={{i.PlayerID}}" target="_blank">{{playerdetails.0.FirstName}} {{playerdetails.0.MiddleName}} {{playerdetails.0.LastName}}, Birthdate: {{playerdetails.0.Born |date("d.m.Y") }},  (PlayerID: {{i.PlayerID}})</a>
    <br clear="all">
{% endif %} 
{% endfor %}
  • In Action: