diff --git a/docs/templates.md b/docs/templates.md index 95155bea..28878c87 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -655,9 +655,9 @@ structured-content generation. {{#formatGlossary dictionary}}{{{definitionEntry}}}{{/pitchCategories}}
- * _`@dictionary`_
+ * _`dictionary`_
The dictionary that the glossary entry belongs to. - * _`@definitionEntry`_
+ * _`definitionEntry`_
The definition entry object in raw form.
@@ -674,6 +674,74 @@ structured-content generation.
+### `hasMedia` & `getMedia` + +Checks to see if a certain type of media is available for a card and injects the relevant content. +These functions are used together in order to request media and other types of optional asynchronous content. + +
+ Syntax: + + {{#hasMedia type args...}}{{/hasMedia}}
+ {{#getMedia type args... [escape=true|false]}}{{/getMedia}}
+ + * _`type`_
+ The type of media to check for. + * _`args`_
+ Additional arguments for the media. The arguments depend on the media type. + * _`escape`_
+ Whether or not the resulting text should be HTML-escaped. If omitted, defaults to `true`. + + **Available media types and arguments** + + * "audio" + * "screenshot" + * "clipboardImage" + * "clipboardText" + * "selectionText" + * "textFurigana" japaneseText readingMode="default|hiragana|katakana" + * "dictionaryMedia" fileName dictionary="Dictionary Name" +
+
+ Examples: + + ```handlebars + {{#if (hasMedia "audio")}}The audio file name is: {{#getMedia "audio"}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "screenshot")}}The screenshot file name is: {{#getMedia "screenshot"}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{#getMedia "clipboardImage"}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "clipboardText")}}The clipboard text is: {{#getMedia "clipboardText"}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "selectionText")}}The selection text is: {{#getMedia "selectionText"}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{#getMedia "textFurigana" "日本語" escape=false}}{{/getMedia}}{{/if}} + + {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{#getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/getMedia}}{{/if}} + ``` + + Output: + ```html + The audio file name is: yomichan_audio_にほんご_日本語.mp3 + + The screenshot file name is: yomichan_browser_screenshot_にほんご_日本語.png + + The clipboard image file name is: yomichan_clipboard_image_にほんご_日本語.png + + The clipboard text is: This is the clipboard text + + The selection text is: This is the selection text + + The selection text is: This is the selection text + + This is an example of text with generated furigana: 日本語にほんご + + The remapped file name for image.png is: yomichan_dictionary_media_1_にほんご_日本語.png + ``` +
+ + ## Legacy Helpers Yomichan has historically used Handlebars templates to generate the HTML used on the search page and results popup.