apostrophe icon indicating copy to clipboard operation
apostrophe copied to clipboard

Add a way to check if the logged-in user is editing the current page from within a template

Open nttfiles opened this issue 1 year ago • 4 comments

The problem to solve

I would like to render some of my custom widgets differently when they're being edited.

Proposed solution

Add an editing property somewhere within the data object, making it accessible from within widget templates.

Additional context

Some examples where this feature would be useful:

  • Removing the link from a button, so the editor doesn't get redirected when trying to edit the button.
  • Making invisible elements (like spacers) visible in edit mode.

nttfiles avatar Aug 09 '24 10:08 nttfiles

You could accomplish this through browser-side JS by checking window.apos.adminBar.editMode. I'm not sure if there is another way on the server-side.

BoDonkey avatar Aug 12 '24 18:08 BoDonkey

I've looked for a way, with no success. Though, for what it's worth, I did find that I could achieve most of what I wanted to do by styling elements differently when they're a child of .apos-area-widget-wrapper.

nttfiles avatar Aug 12 '24 18:08 nttfiles

Can't you check the edit mode and use JS to add a body class to accomplish what you are describing?

BoDonkey avatar Aug 12 '24 19:08 BoDonkey

Probably could. Using CSS does the job for now, but I'll keep that in mind in case I hit a wall. Thanks!

nttfiles avatar Aug 12 '24 19:08 nttfiles