3

I'm currently looking for a neat way to preview content before it gets set live. The ideal setup would be to have a status "draft" that is shown on the frontend to super-admin and maybe other CMS user groups if setup.

I've played with the live look feature but I think it would be nicer to switch the status parameter in the tags depending on the user logged in group_id.

The problem I have come up against is the parsing order.

This post looks like its doing exactly what I want http://themetaq.com/articles/a-better-way-to-preview-entries-in-expressionengine but couldn't get this to work.

I want to keep this as out of the box as possible, rather than a using an add-on.

Thanks!

3
  • What exactly couldn't you get to work from the article? There are three options listed there. Oct 31 '13 at 10:47
  • I got the varible coming out from stash fine but not when it was added into the entry tag. I added the parse="inward".
    – Garth
    Oct 31 '13 at 11:32
  • BTW, Stash (and Low Variables, imo) should be consider a part of the EE box now because of how it helps performance. Using defaults methods will usually require a performance hit. Oct 31 '13 at 11:50
1

[Edited]

If you are using Low Variables (or some other add-on) that allows global variables to be parsed early, you can do this...

--ORIGINAL POST--

The way to do this without an add-on is to use a snippet with simple conditionals.

Create a snippet sn-statuses with:

{if logged_in_member_id == "1"}Open|Draft{/if} 
{if logged_in_member_id != "1"}Open{/if}

Then, in your template, pull in the snippet:

{exp:channel:entries channel="my_channel" status="{sn-statuses}"}
4
  • 1
    I don't believe this works because logged_in_member_id are global variables. They are parsed after the exp:channel:entries.
    – Sobral
    Oct 31 '13 at 11:35
  • Dangit. I have Low Variables installed. :) Oct 31 '13 at 11:37
  • Perfect. But rather than Low Variables, which looks cool but I wanted to avoid the additional expense for each client site, I used the link extension.
    – Garth
    Oct 31 '13 at 12:06
  • @StephenCallender, please, add a warning to your answer. If you to move the user related variables to be parsed early, you should never, ever, ever to enable the page template.
    – Sobral
    Nov 2 '13 at 12:14
1

I prefer to always work without add-ons, if I can.

I use to create a snippet with this code and put it inside the exp:channel:entries:

{if status !="open" OR entry_date > current_time}
    {if author_id != logged_in_member_id AND logged_in_group_id != 1}
        {redirect="404"}
    {/if}
{/if}

If open isn't the only status the users can see, you can improve the code:

{if status != "open" && status != "featured" OR entry_date > current_time}
    {if author_id != logged_in_member_id AND logged_in_group_id != 1}
        {redirect="404"}
    {/if}
{/if}

I prefer to check for status that are different for the open ones because, sometimes, a new one can be created and maybe it shouldn't be viewed yet.

2
  • I like this method and think for an add-on-free option, this is best. Instead of redirecting, I'd probably just say, "This page is not available for viewing (yet). Check back later." Oct 31 '13 at 11:58
  • The live view links use entry_ids and usually the final URLs of an entry use entry_title. So, I believe it's better to not call the users to come back later. Plus, you gonna need an {if:else} for this.
    – Sobral
    Oct 31 '13 at 12:06
1

The Stash method.

(I know you want an add-on-free version, but why? Stash is free, supported, and helps with performance.)

Toward the top of your template set the statuses based on the group_id of logged in member.

{exp:stash:set name="statuses"}{if group_id == "1" || group_id == "6"}open|draft{if:else}open{/if}{/exp:stash:set}

Then get that variable in your channel entries tag pair.

{exp:channel:entries status="{exp:stash:get name='statuses' parse_tags='yes' parse_conditionals='yes'}" channel="my_channel" dynamic="no" parse="inward"}
  {exp:stash:set_list name="blog_listing" parse_tags="yes"}
   ....
2
  • By Add-on free i mean avoiding a feature full module type thing which is an extra thing that clients need to be told about. Actually stash or global_member_vars (mentioned above) are ideal. And your idea about creating the snippet which betters embedded into the entries tag is great- thanks!
    – Garth
    Oct 31 '13 at 11:58
  • Cool. Glad to hear. Whichever method you choose, please be sure mark it correct when the site allows you. :) Oct 31 '13 at 12:00
0

I have developed a small add-on for this. It essentially creates/turns some user variables into early global config vars

This extension adds logged_in_member_id and logged_in_group_id to the global variables array so they are parsed early and can be used in simple conditionals.

  {if logged_in_member_id != "0"}
    {exp:channel:entries status="open|members_only"}
    ...
    {/exp:channel:entries}
  {/if} 
  {if logged_in_member_id == "0"}
    {exp:channel:entries status="open"}
    ...
    {/exp:channel:entries}
  {/if}

If you rely, for some reason, on logged_in_member_id being parsed late, the extension also adds global_member_id and global_group_id for convenience.

http://devot-ee.com/add-ons/global-member-vars

4
  • 1
    Okay sounds good. Can you add the conditional inside the entry tag to avoid duplicating them?
    – Garth
    Oct 31 '13 at 11:33
  • i think so, because it is now an early config var. But don't make it an advanced conditional, otherwise it is parsed late again. e.g. make it two simple conditionals {if global_group_id=="6"}...{/if}{if global_group_id=="0"}..{/if}
    – GDmac
    Oct 31 '13 at 12:23
  • Download link for this add-on no longer works. Oct 29 '14 at 22:39
  • Thanks for the heads up - devot-ee page updated. Do know however, that this extension might not be needed anymore for EE 2.9+
    – GDmac
    Oct 30 '14 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.