Dictionary Inline Expressions

From MSX - Wiki
Revision as of 12:20, 18 January 2021 by Benzac (talk | contribs)
Jump to navigation Jump to search

It is possible to add entries from the dictionary with inline expressions. The expression has the syntax {dic:{KEY}} or {dic:{KEY}|{DEFAULT_VALUE}}. The {KEY} part must be replaced with the dictionary entry key and the {DEFAULT_VALUE} part can be replaced with the default value that is used if the entry is missing. If the entry is missing and no default value is indicated, the expression is removed. It is also possible to add colored dictionary entries with the expression syntax {txt:{COLOR}:dic:{KEY}} or {txt:{COLOR}:dic:{KEY}|{DEFAULT_VALUE}}. Please see Colors for possible values. This feature is available since version 0.1.120.

Since version 0.1.123, you can also wrap dictionary default values with this extended inline expression {dix:{KEY}}{DEFAULT_VALUE}{dix}. The suffix {dix} can also be omitted if it is at the end of the content string. This allows you to set complex default values that use other inline expressions.

Please see following example.

Example[edit]

Screenshot[edit]

Example Screenshot (Dictionary Inline Expressions)

Code[edit]

{
    "headline": "Dictionary Inline Expressions",
    "dictionary": "http://msx.benzac.de/dic/test.json",
    "pages": [{
            "items": [{
                    "layout": "0,0,12,6",
                    "color": "msx-glass",
                    "text": [
                        "Test Entry: '{dic:test}'.{br}",
                        "Test Entry: '{dic:test|Not Found}'.{br}",
                        "Missing Entry: '{dic:missing}'.{br}",
                        "Missing Entry: '{dic:missing|Not Found}'.{br}",
                        "Colored Test Entry: '{txt:msx-blue:dic:test}'.{br}",
                        "Colored Test Entry: '{txt:msx-blue:dic:test|Not Found}'.{br}",
                        "Colored Missing Entry: '{txt:msx-blue:dic:missing}'.{br}",
                        "Colored Missing Entry: '{txt:msx-blue:dic:missing|Not Found}'.{br}",
                        "Complex Test Entry: '{col:msx-white}{dix:test}{ico:msx-red:error} {txt:msx-red:Not Found}{dix}{col}'.{br}",
                        "Complex Missing Entry: '{col:msx-white}{dix:missing}{ico:msx-red:error} {txt:msx-red:Not Found}{dix}{col}'.{br}"
                    ]
                }]
        }]
}

Demo[edit]