I’m developing a custom Shopify theme and need to give merchants control over padding and margin values for sections, but I want to balance flexibility and ease of use.
Global Padding/Margin: The basic requirement is to allow merchants to set a global padding or margin value for the whole section.
Individual Padding/Margin: For more advanced control, I want merchants to be able to adjust padding and margin for individual sides (top, bottom, left, right).
My current problem is that I want the "Individual Padding/Margin" options to be shown conditionally based on whether the merchant has enabled this option. When they enable it, individual controls for each side should appear.
I’ve set up the following schema to control global padding and an "Enable Individual Padding" checkbox. However, I’m facing difficulty hiding the individual padding controls based on whether this checkbox is checked.
Here is the code I have so far:
{
"type": "number",
"id": "global_padding",
"label": "Global Padding (Top, Bottom, Left, Right)",
"min": 0,
"max": 100,
"step": 5,
"default": 20
},
{
"type": "checkbox",
"id": "enable_individual_padding",
"label": "Enable Individual Padding (Top, Bottom, Left, Right)",
"default": false
},
{
"type": "number",
"id": "top_padding",
"label": "Top Padding",
"default": 20,
"hidden": "{{ section.settings.enable_individual_padding == false }}"
},
{
"type": "number",
"id": "bottom_padding",
"label": "Bottom Padding",
"default": 20,
"hidden": "{{ section.settings.enable_individual_padding == false }}"
},
{
"type": "number",
"id": "left_padding",
"label": "Left Padding",
"default": 20,
"hidden": "{{ section.settings.enable_individual_padding == false }}"
},
{
"type": "number",
"id": "right_padding",
"label": "Right Padding",
"default": 20,
"hidden": "{{ section.settings.enable_individual_padding == false }}"
}
Issue:
The hidden property doesn’t seem to work as expected in the Shopify section schema.
The "Enable Individual Padding" checkbox doesn’t conditionally show or hide the individual padding inputs.
What I’m Looking For:
A correct approach to conditionally show or hide input fields (for individual padding controls) based on another setting (the checkbox).
If Shopify’s schema doesn’t support the "hidden" property as expected, how can I achieve this functionality?
Any references or resources that explain how to manage conditional visibility of settings in Shopify sections would be appreciated.
2
Answers
you can achieve the desired functionality through a combination of schema organization and custom JavaScript.
You just need to use the CSS & the schema settings value.
Please check the below sample schema & CSS. I used the
.section-{{ section.id }}-padding
as the selector, so please add the class at the top for the div element.CSS: