ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Customized conditional variables

March 15, 2011 10:07am

Subscribe [3]
  • #1 / Mar 15, 2011 10:07am

    James.Lex

    11 posts

    Hi!

    Is there a solution where I can create my own conditional variables?

    For example: I want to have a customized variable called {allowed_member_groups}

    In the allowed_member_groups variable, I can declare the groups I want. I tried this with snippets but didn’t work.

    The snippet content is

    member_group==1 || member_group==10 ||member_group==8

    So it should be something like this:

    {if allowed_member_groups}
     Stand-alone-entry-form CONTENT
    {if:else}
     No access
    {/if}

    My goal here is to let the specified groups to have access with the Stand-alone-entry-form ONLY.

    I am not sure if this solution is the best. Maybe some of you have a brighter idea than this.

    best regards,
    Jay

  • #2 / Mar 15, 2011 8:46pm

    Lisa Wess

    20502 posts

    Hi, James -

    Snippets are parsed at the same time the templates are; as if they’re inline.  They do not change parse order.

    This may be a good case for a simple plugin where you can set those member groups right in the file, especially if you need to re-use this in many places.  There isn’t a way, outside of a plugin, to do this, though. 

    If you’re interesting, here are the Developer Docs to get you started.

    Does that help?

    Edit to add: With the SAEF or SafeCracker (and we do recommend using SafeCracker now instead), the form won’t show unless you’re logged in with a member that can post to that channel.  For your particular example, a special conditional shouldn’t be required.  EE handles that.

  • #3 / Mar 16, 2011 5:46am

    JusTyMe

    76 posts

    If you’re interesting, here are the Developer Docs to get you started.

    Thanks for the suggestion. I do can CI actually but I am building a strong foundation with EE for now. That would be my next step actually. To work with CI on top of EE.

    Edit to add: With the SAEF or SafeCracker (and we do recommend using SafeCracker now instead), the form won’t show unless you’re logged in with a member that can post to that channel.  For your particular example, a special conditional shouldn’t be required.  EE handles that.

    I am using safecracker already but as far as I understand what you mean. Safecracker will do the magic if a user is authorized or not. I didn’t know about that. I will try it.

    Thanks,
    Jay

  • #4 / Mar 16, 2011 6:13am

    JusTyMe

    76 posts

    the form won’t show unless you’re logged in with a member that can post to that channel.

    By the way, I have an edit link to the SAEF. How is it possible to hide this link to members that has no priviledge to post to a certain channel?

    Maybe something like

    {if user_cant_post}
     You are not allowed to post in this channel
    {if:else}
     SAEF
    {/if}

    Any idea?

    Thanks
    Jay

  • #5 / Mar 16, 2011 1:52pm

    Lisa Wess

    20502 posts

    This is the conditional I use to hide the edit link to get to the SafeCracker form =)

    {if author_id == logged_in_member_id OR logged_in_member_group == "1"}
    • <a href="http://{path=thoughts/edit/{url_title}}">Edit This</a>
    {/if}

    I specify which member groups there, so you will need to know which member groups you allowed to post to that channel.

    Does that help?

    [Edit]  Sorry, that’s to edit.  To post:

    {if logged_in_member_group == "1"}
    <a href="your_url">
    {/if}
  • #6 / Mar 16, 2011 1:59pm

    Brandon Jones

    5500 posts

    Hi Jay,

    There are a few approaches that will likely involve a bit of custom development, so moving this over to the CodeShare Corner.

  • #7 / Mar 16, 2011 8:13pm

    JusTyMe

    76 posts

    This is the conditional I use to hide the edit link to get to the SafeCracker form =)

    {if author_id == logged_in_member_id OR logged_in_member_group == "1"}
    • <a href="http://{path=thoughts/edit/{url_title}}">Edit This</a>
    {/if}

    I specify which member groups there, so you will need to know which member groups you allowed to post to that channel.

    Does that help?

    [Edit]  Sorry, that’s to edit.  To post:

    {if logged_in_member_group == "1"}
    <a href="your_url">
    {/if}

    Thanks for the input but that is actually the solution that I am doing now. I am sorry to tell you but I think this is a bit dirty. I mean having the same condition to multiple SAEF templates is a mess.

    Thanks anyway.

    Jay

  • #8 / Mar 16, 2011 8:20pm

    Lisa Wess

    20502 posts

    Hi, Jay -

    A plugin to check this more dynamically would be a great solution.  There may be one on Devot-ee, but otherwise you can have a look at our Dev Docs for information on how to build your own plugin.

  • #9 / Mar 21, 2011 8:26am

    JusTyMe

    76 posts

    Just coming back for a simple solution just in case someone will be needing this feature without the help of add-ons. I ended up creating a snippet called {edit_article} where I can use it anywhere.

    Here is the content of the snippet. Now I can reuse it anywhere and it is just a breeze adding or removing member groups that can access the link

    {if member_group==1 || member_group==8}
     <a href="http://link">Edit</a>
    {/uf}

    Thanks for your help anyway.

  • #10 / Mar 21, 2011 12:04pm

    Lisa Wess

    20502 posts

    Right, that was what I recommended? I’m a bit confused.  That’s also what’s in the Agile demo. =)

  • #11 / Mar 23, 2011 4:22am

    JusTyMe

    76 posts

    Right, that was what I recommended? I’m a bit confused.  That’s also what’s in the Agile demo. =)

    Partially 😉 Thanks for the support Lisa, I really appreciate it.

    cheers

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases