twig: calculate and sort JSON-data

If you want to sort and calc JSON-data the PRO-Version is needed.


Example-JSON: https://api.json-content-importer.com/extra/json/twig-calc.json


{
"duel_id": 2, "name": "john",
"xp": 5214, "level": 8,
"xp_percentage": 0.56247, "games": 12,
"wins": 6,
"champions": [
{
"champions_id": 25, "champions_name_key": "hero",
"damagedealt": "317", "damagetaken": "458",
"matchtime": 612, "games": 98,
"wins": 2, "xp": 234
},
{
"champions_id": 2775, "champions_name_key": "htgjero",
"damagedealt": "31777", "damagetaken": "5458",
"matchtime": 6512, "games": 958,
"wins": 52, "xp": 2354
}]}

JCI-Template:

  • name: calctwig
  • URL: see above
  • twig-template:
xp: {{xp}}, xp_percentage: {{xp_percentage}}<hr>
{% for ch in champions |reverse(champions_id) %}
champions_id: {{ch.champions_id}}<br>
champions.matchtime: {{ch.matchtime}}<br>
({% set mt_min= (ch.matchtime/60)|round %}
min: {{mt_min}} sec: {{ch .matchtime-60*mt_min}})<hr>
{% endfor %}

Shortcode:

[[jsoncontentimporterpro nameoftemplate="calctwig"]]

In action:

xp: 5214, xp_percentage: 0.56247
champions_id: 2775
champions.matchtime: 6512
(min: 109 sec: -28)
champions_id: 25
champions.matchtime: 612
(min: 10 sec: 12)