platformOS Community

How Do I Use HTML Markup in New Liquid Syntax

DBARNES Mar 14 2021 at 15:02

I'm trying to switch to the new liquid syntax but I I don't see how to use HTML markup within the liquid block and I can't find any documented examples. I guess I could use a partial instead. Is that best practice?

Old way:

{% if id %}
<h1>The id exists.</h1>
{% else %}
<p>{{ result.errors }}</p>
{% endif %}

New way?

{% liquid
if id
???
else
??? echo result.errors ???
endif
%}
Maciej.Krajowski Mar 14 2021 at 16:05
{% if id %}
  <h1>The id exists.</h1>
{% else %}
  <p>{{ result.errors }}</p>
{% endif %}

Is equivalent to

{% liquid
  if id
    echo "<h1>The id exists.</h1>"
  else
    echo "<p>" | append: result.errors | append: "</p>"
  endif
%}

But we are not recommending using the new liquid syntax for this use case - building string as in this example is painful.

  • DBARNES Mar 14 2021 at 16:18
    Ah I see. So is this new syntax something that you guys came up with? I can't seem to find much documentation on it. I'm wondering for example if you can include a partial in a liquid block where the partial has liquid code in it or other liquid blocks.
  • Rich - One Orange Cow Mar 16 2021 at 11:12
    We only use it in functions or code we're not going to touch (or debug) for a long time... otherwise you have to write alot more code and use up alot more lines.
  • Maciej.Krajowski Mar 16 2021 at 20:02
    This is not something we have come up with, this is part of the official liquid implementation. It's great for functions (function tag is pOS extension :) ) , it's bad for mixing it with the HTML (or tags like capture in general).
Please sign in or fill up your profile to answer a question