I’m trying to make a published/unpublished toggle for an element by wrapping it in a div with data-fred-render="{{published}}". My published option set looks like this:
When set to true it returns the value 1, but when setting the toggle to false it doesn’t return a value until I rebuild the Fred theme, so the element is still displayed when logged out of Fred.
Definitely a bug. The data-fred-render requires the text “true” or “false”. So I just use a text field, and enter what I want in the options panel when editing.
Since admins tend to forget to look at their site after logging out of the Manager/Fred I also added a class for items that are unpublished so they’re distinguished from other content. Just so you don’t think something is published when it’s not.
In the element:
{% if published == 'false' %}
<div class="unpublished">
{% endif %}
Element code here...
{% if published == 'false' %}
</div>
{% endif %}
And in the css:
.fred--active .unpublished {
opacity: .3;
}
I’m sure there are clearer ways to show something is unpublished but that was the easiest way I could think of right now.
Ah, no worries. I thought for a second you could call data-fred-render in the css somehow to set a specific style when it’s set to false. That would have been neat
Aaaaah, yes! I love css I’ve been using it for two decades but I still learn new things every day
Just realised though that it would affect other things as well, such as the instructions for the admin. This is a bit off topic I guess but do you know if there’s any way of targeting something that has [data-fred-render=“false”] AND a class? I tried all of the below without any luck.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.