statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

FR: Variable that is only available in Live Preview #2397

Closed macbruker closed 5 years ago

macbruker commented 5 years ago

I have this collapse/expand block on my site. When I am editing with Live Preview, my collapse/expand block is displayed in its default collapsed state, with no possibility to expand it and see the content inside. Clicking to trigger expanding, seems to be prevented in some way.

It would be handy with a variable like {{ preview }} or something similar, that returns true if a page is viewed in Live Preview. That way, I can make sure that the collapse/expand block is always expanded when using Live Preview.

madsem commented 5 years ago

similar issue, trying to find a way to detect live preview as well. This should be included somehow. For me I'm trying to prevent adsense from being included in live preview which is really against adsense policies (don't shows adsense in frames). With many editors working ad impressions can quickly go in the thousands...

madsem commented 5 years ago

ah okay solved it @macbruker, there already is a way to check. You have to check if $_POST['preview'] isset and is not 1.

In Antlers just like this:

{{ if ! post:preview }}
blah
{{ /if }}
macbruker commented 5 years ago

That is awesome! Thank you for sharing your findings 🙂