-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Hey,
I believe that showing errors is the right default for Shopify as a platform. However, I am taking a modular approach to building Shopify themes, and it would be helpful to have a safe option to opt out of this feature.
Please consider having a way to deal with errors that's not based on strings.
Example
I have a reference theme that uses an icon via a liquid snippet:
{{- 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content -}}
To override the default icon in a project, I want to check if a custom icon exists. If it doesn't exist, I will fall back to the default icon:
{%- liquid
capture custom_svg
echo 'custom-' | append: 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
endcapture
if custom_svg_tag != blank
echo custom_svg
else
echo 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
endif
-%}
This doesn't work because custom_svg contains an error instead of being empty. Now, I'm forced to look for an error message or validating the output:
assign custom_svg_tag = custom_svg | slice: 0, 5
if custom_svg_tag == '<svg'
echo custom_svg
else
echo 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
endif
This is definitely not optimal. We have tried this approach for translations in the past, and the error message changed a few times, causing our setup to break.
Another important use case with the same approach is rendering snippets. If there is a custom- version of a snippet it should be used, else it should use the default.
Suggestions
From favorite to least favorite:
| or_blankor| filter_errorsfilter to replace errors withblank. Usage:assign custom_svg = custom_svg_raw | or_blankif custom_svg != blankerroras a value similar toblankorempty. Usage:if custom_svg != errortrycapturetag. Usage{% trycapture %}{% endtrycapture%}- Last resort is to disable outputting errors for a file somehow