Skip to main content

WebApps - Use function tags to retrieve collections

This is an include I’m using to retrieve a collection:
{%- include 'webapp' id: '38623' collection: true -%}
{%- assign hero = context.exports.webapp_38623.data.result -%}
You could add a return statement to the end of your webapp partial that provides collection data. That would effectively make the difference between the two modes dependent on whether the person uses an include tag or a function tag. If they use an include the return statement is ignored, but the layout is returned. If they use a function tag, the layout isn’t returned, but the return variable is. That would make it possible to skip the second line of my code snippet above, looking instead like this:
{%- function hero = 'webapp' id: '38623' -%}
The possible downside is that the rendering logic would still occur even if it wasn’t being outputted. I wonder if there is a way for a partial to identify the tag used to call it.

Log in to comment and vote

No comments yet

Be the first to share your thoughts.