Using visible_if to show/hide resource inputs

Up until last week, visible_if could be used to show and hide resource inputs (product, collection, page) as long as the conditional was based on the value of a supported input type (checkbox, select, etc).

Not being able to use visible_if to toggle between collection and product_list inputs would be a big loss. The conditionals still work in the theme editor but Shopify throws an error preventing file-save. I made a reproduction code gist here.

To clarify, the use case is to show/hide resource inputs based on the value of supported input types, select and checkbox. This use of visible_if still works in the theme editor, but I can’t touch any file that uses it.



1 Like

Update: This appears to be specfic to /blocks schema. These settings will save and work correctly in seciton-level settings and classic block settings.

Running into same problems as you with my /blocks which were working fine with the visible_if until yesterday! Super frustrating.

@Gideon We don’t allow conditional resource settings, this is an intentional limitation as it conflicts with closest.<< resource >>. The fact that it worked up until now was a gap in our validation. You can find the list of supported conditional settings here.

Update: This appears to be specfic to /blocks schema. These settings will save and work correctly in seciton-level settings and classic block settings.

Let me verify, but I believe this is another gap that we’ll be addressing in the near future.

Not being able to gatekeep those is big loss for merchant usability imo. I think the visible_if is great at making the schema settings in theme editor more merchant friendly and this feels like big loss on that regard.

1 Like

I understand why it would be problematic to parse a conditional statement that depends on the value of a closest resource.

This conditional uses a select input.

The docs do not differentiate between settings that can be used in a conditional statement and input types that can be shown/hidden. It seems like those are two very different things?

1 Like

Here is a more concrete example:

This should not work. It requires context to resolve the value of closest.

{
  "type": "checkbox",
  "id": "checkbox",
  "label": "Checkbox",
  "visible_if": "{{ block.settings.product != blank }}"
},
{
  "type": "product",
  "id": "product",
  "label": "Product",
}

This should work. This does not need to resolve the value of closest.

{
  "type": "checkbox",
  "id": "checkbox",
  "label": "Checkbox"
},
{
  "type": "product",
  "id": "product",
  "label": "Product",
  "visible_if": "{{ block.settings.checkbox == true }}"
}

@Gideon There are two separate restrictions to know:

  1. Conditional settings can’t access runtime context or values from resolved data sources. This is aligned with what you are saying.

  2. Only the inputs listed under The following settings support conditional settings on that page can be shown or hidden conditionally. product and collection are not on that list, so you can’t use conditional logic with them. I’ll update the documentation to make this more clear.

@misha with all due respect point number 2 is absolutely ridiculous.

I can accept that we can’t use the value of a resource input for another setting’s visible if condition. However, the fact that resource inputs are completely blocked off from visible if, is just insane. I don’t mean to ask too much but I think the community needs some detail on this as to why this is the way things are at the moment. We have an explanation for point 1, so what about point 2?

Regardless of visible if hiding or showing an input our liquid code already has to handle fallbacks and managing input data when the conditions have it hidden. So it can’t be something like “well it’s just a data point we wouldn’t want to have hidden but still referenced in code”.

Honestly it seems like a blatant code mistake that the resource input types were just blanket excluded.

4 Likes

Make visible_if work for all settings, add a warning in the documentation and leave the specifics to us, that’s our job. The feedback is real and the requirement is clear, make it happen please !

There is no point in having this visible_if property if we need to tiptoe our way using it.

3 Likes

I have raised this issue for a long time but now there is a clue and they have not done it properly.

1 Like

@PeterParker Glad Spiderman got our back on this one !

4 Likes

@Matthew_Crigger I get it, and you’re right to call this out. It does feel like an arbitrary limitation.

There are technical reasons why resource inputs can’t work with visible_if right now, but sadly I can’t get into the specifics of what those are. This isn’t a permanent decision - it’s just not on our roadmap right now.

Thanks for the feedback though - it helps us understand where the pain points are.

Really not a fan of the way this was handled :face_with_diagonal_mouth:

Speaking from experience, the documentation can sometimes be a little light on, and needing to reach for documentation to validate that a feature, which is working in the OSR / OSE, is officially sanctioned is not realistic.

When sections are marked as invalid, the OSR does not fail gracefully, it invalidates the entire route that consumes the template and 404’s.

While there are some guards in place to limit the production impact for a merchant on a breaking change like this, this breaking change has felt like it’s flown a little close to the sun.

Let’s take the following scenario:

  • Merchant duplicates a theme that is currently working, because the section was previously marked as valid.
  • Since the section is marked as invalid on duplication, templates now referencing said section are now invalid, and 404.
  • Merchant goes through and updates un-affected templates, not realising that the duplicate theme now has invalid routes. Because they are only updating unaffected templates, they don’t realise parts of their sites are 404’ing.
  • Merchant goes to publish said theme.
  • Theme publishes successfully.
  • Merchant is now 404’ing on the product route.

The merchant was at no point:

  • Notified that the theme duplication process did not work.
  • That routes would now 404 if a template included the affected section.
  • Prevented from publishing a broken theme.

I think there would have been far more graceful ways of deprecating a feature that once worked.

4 Likes

@misha this is a big breaking change. We’ve had to submit a new version of our themes in a hurry as some sections could not be added anymore (and as Kurt explained, if a JSON file such as index.json were referring one of those sections, the whole file won’t upload and generate a 404). Shopify has usually cared a lot about BC, it is surprising that a BC was done (without prior communication to devs) that can cause such issue.

Just to be sure, I can see that image_picker (which is a resource) is still in the list. Can you please therefore confirm that using this (where logo is an image_picker) still supported and won’t be removed?

{
  "type": "range",
  "id": "logo_width",
  "label": "Width",
  "min": 200,
  "max": 300,
  "visible_if": "{{ section.settings.logo }}"
}
3 Likes

This is going to stop us from making any updates, and with very little heads up !!! We deprectaed some fields using this and now this will be tough to migrate from as well! would request some time atleast to make this change! We were using this in our theme app extensions, so now we are unable to deploy any extensions at all!

1 Like

Confirming that image_picker is fully supported. We made no changes to the list of supported settings.

@Gideon, I can’t help you with the arbitrary conditional logic restriction we’re all running into but I wanted to propose an alternative approach to what you’re doing. My “Product Cards” theme block starts with a URL field. I then use visible_if to look for things like “{{ block.settings.url contains ‘shopify://collections/’ }}“ or “{{ block.settings.url contains ‘shopify://products/’ }}“. If it’s a collection, I have a select input allowing me to select whether I’m showing a single card for this collection or if I’m showing a collections products. If it’s a product URL, simply show the single product card.

This doesn’t help if you want to us the Product List field in your block but in my experience, when I want to add multiple products individually, I can do so just by adding individual Product Card Blocks. I like this approach since it also allows you to create cards for other uses like non-product related links, as well as links to pages, blog articles and other Shopify resources. It also allows me to mix and match so, for example, I can add a block showing products from a collection and precede that with a second block showing a single, featured product (or even a non-product block like an image, content or video).

But yes, I agree with everyone else. Shopify’s need to impose restrictions where it’s not really needed is one of my biggest complaints with the platform. If something will fail if misused, trust us as developers to check for and fix that - just document it so we know. It’s what we have to do for every other type of code/platform so what’s the problem here. If it’s possible but can have some risk, document it and let us choose to use it.

Sorry, one follow up to this. Since “Cards“ generally have a featured image and my cards can be Pages and Blogs as well, this posses a problem since those don’t have featured images natively in Shopify. I work around this by adding a “Featured Image“ metafield to each but the fact that there is no featured image for these core Shopify objects already is very strange IMO. You have them for Products, Collections and Blog posts. For the sake of consistency Shopify, it would be nice if all of these objects were consistent. Just a suggestion.