How to activate-disable / show-hide sections or blocks via liquid?

Hi,

is it possible to hide or show sections or blocks via code? I wand to add a timer functionality, so some blocks will be made visible and hidden at a certain date and time. In the JSON file there is a option or “disabled” when you manually hide a secion/block in theme editor. But is it also possible to do this via code?

A workaround would be to just hide the block with CSS or remove the HTML content via JS. But it would be great, if also the “eye” would be updated, so the icon shows the correct state.

Best,

Thorsten

Thx!

Yes, you can custom code in theme for this.

By this you will be able to set settings to true and false and section will be hidden if select false.

Hey,

thanks for your reply, but where is your solution? How can I do this? Can i access the „disabled“ variable in code?

I have code in below site for announcement which enable on Thursday 12 Est and disable on Saturday after 4Est.

For manual enable disable you customize the section and add button option.

https://ninjatransfers.com/

I can do this for you if willing to hire.

I thought this is a board for helping each other, not for trying to get a job…

1 Like

If a code is short and easy that can be shared but a complete solution can’t be shared hope you understand.

I don’t have asked for a code. It was simple question. I know how to add a checkbox and remove HTML output via CSS or JS, I also know how to add fields for set a timer. But My question was if it is possible to change the status the view-indicator (eye symbol). You don’t gave me an answer to this.

2 Likes

Here is the answer.

Whenever we add a section it appends the entry in the template JSON.

However, being a coder my suggestion would be a custom checkbox, option in the section block.

Hope this is clear to you.

Hi, sorry I saw the answer right now.

Thanks. Yeah, I already told that I know how to add a checkbox and work with this. But this was not my questions.

“In the JSON file there is an option “disabled” when you manually hide a secion/block in theme editor. But is it also possible to do this via code?”

My question is if I can access and set this value through liquid code.

Hi @zorstn ,

You can’t access the JSON disabled attribute but you can add the checkbox and put validation of its state like if checkbox state is checked and write the whole code inside the statement.

By this code will not show when checkbox is not checked

1 Like

That’s all I wanted to know :slightly_smiling_face:

I think my first question was not totally clear. I also have mentioned workarounds etc. sorry that was my fault. Of course I know how to hide code blocks in liquid with conditional statements. The idea with JS was stupid. And I only wanted to know about the json disabled feature :slightly_smiling_face: anyway, many thanks for your help!!

1 Like