espenmn
(Espen)
October 22, 2020, 3:34pm
1
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"
class="fragment-dummy">
<p>Placeholder for hidden fragment</p>
<style>
.fragment-dummy {display: none}
.template-edit .fragment-dummy {display: block}
</style>
</div>
<div tal:condition="not: view/data/disabled">
… all stuff here
</div>
espenmn
(Espen)
October 23, 2020, 4:12pm
2
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 ?
espenmn
(Espen)
October 26, 2020, 1:43pm
4
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.
reinhardt
(Manuel Reinhardt)
October 27, 2020, 6:23am
5
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):
espenmn
(Espen)
October 27, 2020, 12:21pm
6
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).