We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
In your Wagtail, you sometimes may want to vary the template output depending on whether the page is being previewed or viewed live.
It might be as simple as adding a banner to clearly show that you are previewing a page or you might want to disable some tracking code during preview (Google Analytics for example).
Wagtail adds a variable is_preview
to the request you can use to check this:
For example, if you have visitor tracking code such as Google Analytics in place on your site, itβs a good idea to leave this out when previewing, so that editor activity doesnβt appear in your analytics reports. Wagtail provides a request.is_preview
variable to distinguish between preview and live.
So, in your template, you can do:
{% if not request.is_preview %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
...
</script>
{% endif %}
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.