Skip to content

Allow to capture the content of a variable with Qute #46355

@ia3andy

Description

@ia3andy

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 capturetag: 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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions