I’m a newbie to coding and learning hands on as I go. I am working on my company’s website and trying to set up the collection pages a certain way to not show text over the image.
This is the code I am trying to edit in Shopify:
{
“type”: “text”,
“id”: “custom_name”,
“label”: “Custom Name”,
“info”: “If “Custom Name” is empty, title = default custom name”
},
I want to change it so that if the field “Custom Name” is empty, then the title will also be blank or not display anything at all over the image.
I’ve been tinkering with different commands etc but I am a novice and could use some help.
Thanks 🙂
2
Answers
That’s how the variable should look like:
Now you can do a for loop for each one of those but for the example, it’s going to be for the second one:
As a small tip, when showing the text add a
.trim()
so if there is any whitespace, it will be removed!It’s not clear if you like to set the default name to the JSON object or to the output, since the first one is not possible.
You can set a default option to the JSON object using
"default": "something"
, but once that is removed/deleted it will be blank and the default value won’t return.If you like for the output to fallback to a default one, than it’ simple as this:
{{ settings.custom_name | default: 'Something Default' }}
( if this is a JSONsettings_schema.json
file ){{ section.settings.custom_name | default: 'Something Default' }}
( if it’s a section )In case it’s a block in a section, then: