Search code examples
twigapostrophe-cms

How to test if Apostrophe is in "editor mode" in a twig template


I am wanting to apply conditional CSS and template code while my Apostrophe CMS installation in "editor mode." However I have not been able to find anything in the documentation.

I have attempted to use the data.global object and the data.page object with no luck.

I am hoping to use something like

{% if data.global.edit %}
<br>
<br>
{% endif %}

Solution

  • You can check for data.page._edit or data.piece._edit, depending on whether it's a page template or a show.html template for a piece, to see if a user has editing privileges. If you're using apostrophe-workflow and you want to see if the user is in draft mode (edit mode) vs live mode you can check data.workflowMode as well.