liquid icon indicating copy to clipboard operation
liquid copied to clipboard

WIP - Support {% render obj %}

Open catlee opened this issue 3 years ago • 3 comments

We would like to add support to the render tag so that it can render externally specified blocks by passing in the block object to the render tag.

For example, in a section rendering a set of blocks:

{% for block in section.blocks %}
  {% case block.type %}
  {% when "title" %}
    {{ block.settings.title }}
  {% when "@app" %}
    {% render block %}
  {% endcase %}
{% endfor %}

We've found this useful in Shopify to render 3rd party extensions contained in "app blocks": https://shopify.dev/themes/architecture/sections/section-schema#render-app-blocks

catlee avatar Jan 18 '22 23:01 catlee

Wouldn't it make more sense by using {{ obj }} instead? The render tag was introduced also for its caching semantics which I think this PR is breaking.

sebastienros avatar Feb 01 '22 15:02 sebastienros

We are currently using {% render block %} in Shopify for rendering app blocks: https://shopify.dev/themes/architecture/sections/section-schema#render-app-blocks

We did also consider using constructs like {{ obj }} or {{ obj.render }} but ultimately decided that {% render obj %} was more appropriate for a few reasons:

  • Using a tag gives us the ability to pass arguments if needed, {% render obj, foo: bar %}
  • We already have {% render 'snippet' %} tag which renders a local template file. Rendering application-defined content using the render tag seems like a natural extension of the behaviour here.

I'm hopeful that this functionality will be generally useful, by allowing application specific drops to render themselves.

catlee avatar Feb 03 '22 17:02 catlee

We already have {% render 'snippet' %}

And they explicitly made 'snippet' be only string literal in render when it was introduced to "fix" the include tag so the template could be cached.

I still like the concept but I am concerned it won't be accepted in this form. Might even be easier to sell it in the now defunct include tag ...

sebastienros avatar Feb 03 '22 22:02 sebastienros