Conditional Rendering

use y:if, y:elif, y:else and y:fi control render block conditionally.

y:if

Syntax is y:if="{{ condition }}". if condition is true, then render the block. y:if must be used in the first block.

condition is Comparison and Logical expression.

y:if YAOML

<pet y:if="{{ condition }}"> {{ name }} </pet>

y:if Markdown or Text

<% y:if="{{ condition }}" %>
##{{ name }}
<% y:fi %>
<% y:if="{{ condition }}" %>
{{ name }}
<% y:fi %>

y:elif

Syntax is y:elif="{{ condition2 }}". if condition2 is true, then render the block. y:elif is optional.

y:elif YAOML

<pet y:if="{{ condition }}"> {{ name }} </pet>
<pet y:elif="{{ condition2 }}"> {{ title }} </pet>

y:elif Markdown or Text

<% y:if="{{ condition }}" %>
##{{ name }}
<% y:elif="{{ condition2 }}" %>
##{{ title }}
<% y:fi %>
<% y:if="{{ condition }}" %>
{{ name }}
<% y:elif="{{ condition2 }}" %>
{{ title }}
<% y:fi %>

y:else

if all the condition is false, then render the block. y:else is optional and must be used in the last block.

y:else YAOML

<pet y:if="{{ condition }}"> {{ name }} </pet>
<pet y:elif="{{ condition2 }}"> {{ title }} </pet>
<pet y:else> {{ id }} </pet>

y:else Markdown or Text

<% y:if="{{ condition }}" %>
##{{ name }}
<% y:elif="{{ condition2 }}" %>
##{{ title }}
<% y:else %>
##{{ id }}
<% y:fi %>
<% y:if="{{ condition }}" %>
{{ name }}
<% y:elif="{{ condition2 }}" %>
{{ title }}
<% y:else %>
##{{ id }}
<% y:fi %>

y:fi

Condition block ends tag, used at Markdown or Text type content only.