[SOLVED] TAL condition for 'mosaic edit mode'?

Is there a condition I can check in a theme fragment to 'know if we are in edit mode" ?

I have added an option "disabled" that hides the fragment.

But it would be nice to show it (greyed out) in edit mode instead of an ugly hack, like:

<div tal:condition="not: view/data/disabled" 
    <p>Placeholder for hidden fragment</p>
         .fragment-dummy {display: none} 
         .template-edit .fragment-dummy {display: block}

<div tal:condition="not: view/data/disabled">
… all stuff here

I see that the body tag knows that we are in edit mode:

body class="frontend icons-on   …  template-edit …"

Anyone know where this comes from ?

Thanks a lot.

I came across a 'hidden theme-fragments feature'.

view/request/form shows the fields, but when in Edit mode view/request/form also has _layouteditor: True.

So something like this should work:

def editmode(self):
    form = self.request.form
    if  '_layouteditor' in form:
        return True

UPDATE: I noticed that since the condition is not working as expected if you hide and then want to show again. This will require a save and a new edit.

I am not sure if this feels like a feature, not a bug, though.

We have this:

from plone.subrequest import ISubRequest

    def in_layout_editor(self):
        return not ISubRequest.providedBy(self.request)

... but I'm not sure whether this is hacky as well and/or only works for certain versions of mosaic.

I also found this variant in our code:

if not self.request.get("_layouteditor") or ISubRequest.providedBy(self.request):

I use it in theme fragments so I need to stick to restricted python.

That said: it looks like the same happens when using your approach.

For now: I consider this a feature not a bug, since it makes it easier to make a layout (but requires one extra save if you change your mind).