Nested includes and/or flexible templates



For many reasons (some smarter, others not so much), I’d like to have a note template that supports multiple HTML elements.

For example:

  • note with a paragraph
  • note with a paragraph and an image
  • note with a paragraph, an image, second paragraph, another image
  • note with 3 paragraphs and 3 ordered lists

Having a template, such as the following, allows only having a bunch of text in the note.

Note: {{include.content}}

I could go down the route of having a separate template for each of the cases listed above, but it feels like an overkill.

Also, liquid statements such as:

{% include note.html content=“Some text”
{% include image.html file=“some/path” %}

are obviously not supported.

Is there a way to push another nested HTML chunk within an include in a way similar to the one above??

Is there a way to support multiple HTML markups in the note.html template, but enabling them optionally with if statements… well there obviously is:

{% if include.para1 %}

{% include.para1 %}

{% endif %} etc.

but also, having logic that allows to order them in the way I want to do, such as:

{% include note.html
para1="Some texxt"
para2="Another text"
image1_alt="Some alternate text"

I seem unable to figure out how to do this ordering bit…

This would make a potential note.html file very flexible and would make markup easy to understand and implement.


I would make an page array in the page YML that looks like this:

 - note: This is some text
    - text_html: <p>this is html</p>
      image: /uploads/myimage.jpg

The layout would look like this:

{% for item in page.notes %}
  <h2>{{ item.note }}</h2>
  {% for i in item.contents %}
    {{ i.text_html }}
    {% if i.image %}<img src="{{ i.image }}" />{% endif %}
  {% endfor %}
{% endfor %}

These things can be easily ordered, added and deleted in CloudCannon, where _html fields have a HTML editor. This solves all your cases IMO.


Can you elaborate? I am not sure how this is supposed to work, and also, I am not using and cannot use CloudCannon’s service.


I have updated the answer with the corresponding layout.

This solution works best with a WYSIWYG editor for HTML in combination with a graphical editor for YML arrays. Most CloudCannon, Forestry and others offer these kind of solutions. Why can’t you use CloudCannon?