-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
area/quteThe template engineThe template enginekind/enhancementNew feature or requestNew feature or request
Milestone
Description
Description
Currently, it is not possible to create variable with complex logic.
For example, lets imagine you want to create a variable faClass
(font-awesome) for the icon that represent an admonition block based on the admonition type.
{#when type}
{#is "info"}
fa fa-lightbulb
{#is "warning"}
fa fa-exclamation-triangle
{#is "error"}
fa fa-times-circle
{#is "success"}
fa fa-check-circle
{#is "question"}
fa fa-question-circle
{#else}
fa fa-info-circle
{/when}
Having this code in the <i class=""/>
would be error prone (spaces) and ugly.
For this case we need something similar to Liquid for Jekyll capture
tag: https://shopify.dev/docs/api/liquid/tags/capture
Here is a workaround, but it's not very elegant and user-friendly:
{#fragment id=faClass rendered=false}
{#when type}
{#is "info"}
fa fa-lightbulb
{#is "warning"}
fa fa-exclamation-triangle
{#is "error"}
fa fa-times-circle
{#is "success"}
fa fa-check-circle
{#is "question"}
fa fa-question-circle
{#else}
fa fa-info-circle
{/when}
{/fragment}
<p class="admonition {type}">
<i class="{#include $faClass}"></i>
{nested-content}
</p>
Implementation ideas
{#set}
{#when type}
{#is "info"}
fa fa-lightbulb
{#is "warning"}
fa fa-exclamation-triangle
{#is "error"}
fa fa-times-circle
{#is "success"}
fa fa-check-circle
{#is "question"}
fa fa-question-circle
{#else}
fa fa-info-circle
{/when}
{#as faClass}
<p class="admonition {type}">
<i class="{faClass}"></i>
{nested-content}
</p>
{/set}
jotak
Metadata
Metadata
Assignees
Labels
area/quteThe template engineThe template enginekind/enhancementNew feature or requestNew feature or request