I recommend building output to a string and then outputting the string. To build an html table, one MT method is
Wiki: listFormat() and may be worth looking in to. It requires a comma separated list, but converting a json array to a list is pretty easy.
Code: Select all
[h: data = json.append("","one", "two", "three")]
[H: list = json.toList(data)]
[H: table = listFormat(list,"<table border=1><tr>%list</tr></table>","<td>%item</td>","")]
[R: table]
Here's a snippet of a more complicated use using listFormat. I'm building an input() string.
Code: Select all
...
<!-- define variables locally -->
[H: skillData = json.toStrProp(am.skills)]
[H: skillDataProps = json.fields(am.skills)]
[H: varsFromStrProp(skillData)]
<!-- eval roll mods -->
[H: rolls = listFormat(skillPropNames,"%list","[H: %item.rollMod = %item.rank + 3 * %item.class + eval(%item.ability+'B') + %item.acp * armorCheckPenalty + %item.mod + allSkillsMod]","")]
[H: evalMacro(rolls)]
<!-- get user input -->
[H: abilityNames = "Str,Dex,Con,Int,Wis,Cha"]
[H: colorList = json.set("{}","Str","Red","Dex","Blue","Con","Orange","Int","Purple","Wis","Green","Cha","Black")]
[H: skillInputs = listFormat(skillPropNames,"%list",
'%item.tab|<html><b color=[r: json.get(colorList,"%{%item.ability}")]>%{%item.name}</b> (%{%item.rollMod})</html>|%{%item.name}|TAB ##'+
"header|<html><b>%{%item.name}</b> ( %{%item.rollMod} )</html>|Skill Name|LABEL|span=true ##"+
"%item.rank|%{%item.rank}|Rank|TEXT ##"+
"%item.mod|%{%item.mod}|Modifier|TEXT ##"+
"tip|<html><div width=300><HR>* In most cases, these values remain unchanged<HR></div></html>|Tip|LABEL|span=true ##"+
"%item.ability|%{abilityNames}|Ability|LIST|SELECT=[r: listFind(abilityNames,%item.ability)] VALUE=STRING ##"+
"%item.class|%{%item.class}|Class|CHECK ##"+
"%item.acp|%{%item.acp}|Armor Check|CHECK ##"+
"%item.untrained|%{%item.untrained}|Untrained|CHECK ","##"
)]
<!-- convert strprop to be used in input -->
[H: skillInputs = evalMacro(strformat(skillInputs))]
<!-- ##### INPUT ##### -->
[H: abort(input(skillInputs))]
...