Hiding Metafield sections & blocks when they're empty

A quick and easy way to conditionally show or hide sections & blocks based on if they have Metafield content, or if the Metafield is blank.
📢 STAY UPDATED
Subscribe to my newsletter: ed.codes/newsletter
KZread won’t always show you my latest videos, subscribe to be notified and see other content that I don't post on KZread.
🙏 SUPPORT THE CHANNEL ON PATREON
Request and vote on videos, get discounts, and be listed as a community member.
/ edcodes
📚 MY SHOPIFY CODING EBOOK
ed.codes/shopify-coding-handbook
Learn HTML, CSS and Shopify Liquid from the beginning and specifically for Shopify.
👨🏼‍💻 WHO AM I?
Hey! My name is Eduard.
I teach the tech side of starting and running a Shopify store.
I'm a professional web developer, but my goal is to make Shopify easy with simple and straight-to-the-point videos.
Visit my website: ed.codes
Join "Shopify DIY" on Discord
Chat with me and other store owners and developers:
ed.codes/community
🛠 CODE SHOP
ed.codes/shop
Pre-built sections & features for Shopify 2.0 themes, often replacing the need for apps. Copy and paste the code into your theme.
👍 MY FAVOURITE APPS & THEMES
ed.codes/tools
⏭ CHAPTERS
00:00 Example #1 - Blocks
00:39 Example #2 - Sections
01:28 Solutions?
02:57 Sections vs Blocks
03:13 Hiding sections with CSS
06:38 Hiding a block with JS
13:34 Bug fix
15:12 Newsletter & Patreon
#Shopify #Metafields #CustomLiquid

Пікірлер: 33

  • @EdCodes
    @EdCodes6 ай бұрын

    ❗Related video: How to do this without liquid, on any website - kzread.info/dash/bejne/h2R_m9dwfayno9I.html

  • @saucydee1
    @saucydee18 күн бұрын

    I found your videos yesterday. I have little to no coding knowledge but you explain things in a way that I can start to understand it. I'm not about to start writing my own code but I'm beginning to understand the components. Thank you!

  • @HairyNick
    @HairyNick2 ай бұрын

    Absolute life saver, thanks!

  • @_aisolo
    @_aisolo3 ай бұрын

    This is awesome! Just the tutorial I needed! Def subbing!

  • @johnsalimie7886
    @johnsalimie78862 ай бұрын

    this solution didnt work on mobile .. desktop was flawless thank you

  • @Kotenbo
    @Kotenbo4 ай бұрын

    Very helpfull and instructive content, thanks a lot

  • @jencarlson
    @jencarlson3 ай бұрын

    Awesome! This was the only solution that worked. You are amazing!

  • @user-uk4de6zr2g
    @user-uk4de6zr2gАй бұрын

    Thank you so much!

  • @olgagal8800
    @olgagal88006 ай бұрын

    🤗👍 Thank you Ed....

  • @DaveTechover
    @DaveTechover11 күн бұрын

    Hi Ed! Is it possible to add the functionality of using a Dynic source on a part of a section that doesn't? For example, a section with a video. I want to connect a dynamic source to the video URL settings but it doesn't have the option to connect a dynamic source. Is there a way around that?

  • @SanjitSutroDhor
    @SanjitSutroDhor6 ай бұрын

    Awesome tutorial Ed. I'm new to shopify and learning. Your Videos are helping me a lot. I want to request you please make a tutorial on how we can create custom section where client will be able to change content of the section.

  • @londelidess
    @londelidessАй бұрын

    My sensei

  • @justame7638
    @justame76382 ай бұрын

    Off topic. How can I update my theme without loosing any code? Im using dawn 12, but now theres dawn 13.01. I have so much coding style its dawn on steriods, and do not want ot loose anything.

  • @Human_Evolution-
    @Human_Evolution-6 ай бұрын

    Great stuff. If someone is not using a git repo, this is the best. I have not used custom code blocks yet, might be fun for stores that do not want to invest a lot of time.

  • @EdCodes

    @EdCodes

    6 ай бұрын

    For professional developers there are better ways to get this done. But I love the possibilities custom liquid blocks open up for amateur coders.

  • @Human_Evolution-

    @Human_Evolution-

    6 ай бұрын

    Yes and for sites that only need a small amount of custom code. I had a project last month that only had 1 custom feature asked from the store owner, we ended up not doing it because he did not want to create a GitHub repo, but I might have been able to use this little custom code blocks. Thanks @@EdCodes

  • @DavidCouillard
    @DavidCouillard6 ай бұрын

    Keep sharing those small tips Ed! Love them! I don’t think this javascript trick would work with a multi-language website right? Since, in this case, the word « ingredients » would change based on the visitors language.

  • @EdCodes

    @EdCodes

    6 ай бұрын

    It depends on the theme. Upon inspecting the code, there might be something else you can use - maybe the original language word is visible in the code, maybe it is added to a class name or ID, or maybe you can use the nth-child to target an accordion with specific order as @pedroalfaiate suggests in his comment.

  • @pedroalfaiate
    @pedroalfaiate6 ай бұрын

    Really nice tutorial Ed. Never thought about this possible solution. Thanks for that. By the way, on the second case you might be able to use CSS instead of Javascript. It is possible to apply style to an specific element inside another (the first, the second, the third...) by using something like this :nth-child(2), :nth-child(3) { display:none; } Anyway is just another potential solution instead of using javascript. Once again, thanks for the anwsome tutorial.

  • @EdCodes

    @EdCodes

    6 ай бұрын

    I wouldn't like to use nth-child because if they reorder the accordions then this will break and the wrong accordion will be hidden. They might forget about the code by then and not understand what is happening. Another option is new css selectors like :has and :empty but browser support is not great and I didn't want to get too experimental. In a real project I would try harder to avoid JS but for the video I wanted to demo a js solution too. Thanks for the thoughtful comment!

  • @pedroalfaiate

    @pedroalfaiate

    6 ай бұрын

    @@EdCodes makes perfect sense. It is good that you showed both examples. The viewers now can use whatever suits them better. By the way, glad to see you back on youtube.

  • @Irfan-PineappleStudio
    @Irfan-PineappleStudio4 ай бұрын

    Thanks ad , I have a question related to your video , supposed I have "watch now video" collapsible row instead of "ingredients" and if I put meta field value for a product then show it other wise hide it , as you told in this video

  • @davidgoult8694

    @davidgoult8694

    4 ай бұрын

    Hi I believe you would just need to follow the video and were the JavaScript targets title ingredients put your “watch now video “ title.

  • @luiginica
    @luiginica6 ай бұрын

    Thank you! Can't we do something using some condition like "if body of the accordion is empty" then delete it? This would solve the problem for all the empty accordions. This way, we don't have to look for the title of the accordion and we don't have to take care of each accordion. Problem is that I don't know how to check for empty body in an accordion nor if this is even possible. Just an idea.

  • @EdCodes

    @EdCodes

    6 ай бұрын

    Yeah, if you're using javascript then you could probably check if an accordion is empty... although that might be messy. I'd rather just target the specific accordion if possible. There are lots of ways you could do it with javascript, this was just an example. But as I mentioned in another comment, javascript should be a last resort. CSS is much safer and easier.

  • @user-gs4jg1rs6n
    @user-gs4jg1rs6n6 ай бұрын

    👌

  • @Klee87278
    @Klee872786 ай бұрын

    I love u

  • @mcpisik
    @mcpisik6 ай бұрын

    My custom theme has blocks Custom Html & Custom image, but not Custom liquid?

  • @mcneillshiner4718

    @mcneillshiner4718

    4 ай бұрын

    It might work in custom HTML. Our custom theme has a "custom content" block that only mentions HTML, but does also support Liquid and JS

  • @roaldschinkel1668
    @roaldschinkel16682 ай бұрын

    Hi, I want to hide a d-flex element. Can you please help me with that? When I put in this code in the liquid element nothing happens unfortunatly: {% if collection.metafields.custom.collectie_afbeelding_1 == blank %} .d-flex { display: none; } {% endif %}

  • @user-wy7ud1go2s
    @user-wy7ud1go2s3 ай бұрын

    Hi Ed, im doing it to my broadcast theme, its hiding the custom content section but its still hiding for all products even though the metafiels iv states in the {%if collection.metafield.XXXX%} has a value in in it. this is the code im using: {%if collection.metafields.custom.custom.product_page_featured_image_1 ==blank %} #BrickSection--template--17166480474364__imgtxt {display:none;} {%endif%}