Closed ObsidianTTRPGProject closed 11 months ago
Putting this here for reference while looking at how to implement: https://github.com/farling42/obsidian-import-json#new-handlebar-functions
Can you send me a solid test or example usage that I can plug into Foundry and test the implementation?
I'm not entirely sure what I'm looking for, but I've recreated the implementation in Martin's repo.
So, I ran Martin's test and got back the expected response:
Handlebars.compile('{{ more-handlebars-helpers-table "blue" "red" "angry" "blue" "sad" "yellow" "envious" "green" "happy" }}')()
// > 'sad'
I can use that for now. To make it more obvious, I will take the first "blue" and extract it to a JSON prop so that the user can see what is being evaluated.
Here are some situations where we use it.
alignment: "{{table system.details.alignment.value "LG" "Lawful Good" "LN" "Lawful Neutral" "LE" "Lawful Evil" "NG" "Neutral Good" "N" "Neutral" "NE" "Neutral Evil" "CG" "Chaotic Good" "CN" "Chaotic Neutral" "CE" "Chaotic Evil"}}"
size: "{{table system.traits.size.value "ti" "Tiny" "sm" "Small" "med" "Medium" "lg" "Large" "hu" "Huge" "ga" "Gargantuan"}}"
Source Files: Note: These are created with the Foundry Markdown Exporter plugin. Blood Ooze.md Alchemical Drudge.md
Reopening. I meant to allow you to close these issues when you had a chance to test out the new helpers. v1.1.0 is ready.
Thank you. This works perfectly!
Table Lookup A new inline helper "{{table" is available. It is used to lookup a value in a static look-up table and replace it with another value.
The first parameter is the value to be translated into another value. value1 is the value to be compared to the lookup value. result1 is the result of the {{table}} helper if the lookup value is equal to value1 value2 result2 = second set of possible matches etc, as many pairs of value/result as you need. (any/all of the lookup value and value/result values can be fields or fixed strings) value can contain a javascript regular expression result can contain capturing groups (e.g. $1) to copy information from the matching string. {{!-- {{table "blue" "red" "angry" "blue" "sad" "yellow" "envious" "green" "happy"}} --}} {{!-- will be converted into the string 'sad' (taking "blue" and looking for the value/result pair that matches) --}} {{table lookup value1 result1 value2 result2 value3 result3}}
Helper