Using Stash to Create Entry Previews
Over at Meta Q front-end developer Terris Kremer wrote up a tutorial on using the Stash add-on to create entry previews.
Wait, what’s Stash?
Stash allows you to stash text and snippets of code for reuse throughout your templates. Variables can be set dynamically from the
$_GET
or$_POST
superglobals and can optionally be cached in the database for persistence across pages.Stash variables that you create are available to templates embedded below the level at which you are using the tag, or later in the parse order of the current template.
The premise of the tutorial is that existing methods for creating entry previews are too complicated.
There are a few add-ons and methods out there that let site admins preview their ExpressionEngine entries and they all stink.
I disagree with the premise (the solution with Stash ended up being more complicated) but the tutorial is a great demonstration of what you can do with the Stash add-on by Mark Croxton.
Robson Sobral — 00:07 on 04.11.2012
I just put this code into a snippet and use around all website:
{if status==‘draft’}{if logged_in_group_id != ‘1’}{if logged_in_group_id != ‘5’}{redirect=‘404’}{/if}{/if}{/if}
In this case, I have a group for administrators, 1, and one for authors, 5.
This works really well for me.
Robson Sobral — 23:29 on 04.16.2012
Improving:
{if status==‘draft’}{if logged_in_group_id != ‘1’}{if logged_in_group_id != ‘5’}{redirect=‘404’}{/if}{/if}{/if}
{if ‘{entry_date}’ > ‘{current_time}’}{if logged_in_group_id != ‘1’}{if logged_in_group_id != ‘5’}{redirect=‘404’}{/if}{/if}{/if}