Twig: calculate and sort JSON-data

If you want to sort and calulate JSON-data the PRO-Version is needed and the twig-parser.


Example-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
}]}

Template for the Plugins Template-Manager:

xp: {{xp}}, xp_percentage: {{xp_percentage}}
{% for ch in champions |reverse(champions_id) %}
champions_id: {{ch.champions_id}}:
champions.matchtime: {{ch.matchtime}}
({% set mt_min= (ch.matchtime/60)|round %}
min: {{mt_min}} sec: {{ch .matchtime-60*mt_min}})
{% endfor %}

Shortcode:

jsoncontentimporterpro url=http://api.json-content-importer.com/extra/json/twig-calc.json parser=twig id=NO_OF_TEMPLATE

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)