Rather than using append and prepend Jekyll filters, you code can look more natural using capture.


{%- capture my_var -%}
/api/{{ name }}.json
{%- endcapture -%}

You can do multiple lines.

{%- capture foo -%}
abc {{ name }} def
xyz 123
{%- endcapture -%}

Trim whitespace

That is fine for most purposes.

Note that if you subsitute in a string, you’ll get a multi-line value.


const value = "

So trim it.

{%- capture my_data -%}
/api/{{ name }}
{%- endcapture -%}

Note use of - before and after the value, to avoid the newlines. Using - on the outer of the entire capture doesn’t work.


{% capture my_data %}/api/{{ name }}{% endcapture %}