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.

Change the parse order of a standard global variable?

June 14, 2008 9:33pm

Subscribe [3]
  • #1 / Jun 14, 2008 9:33pm

    S. Lee Ware

    39 posts

    I want to change the order in which a particular standard global variable is parsed (group_title) - moving it earlier in the series.

    Is this possible?  I want to build a large portion of site functionality around having this variable available earlier in the parsing order.

    Any input is appreciated.

  • #2 / Jun 15, 2008 12:40am

    Luke Stevens

    80 posts

    Fresh Variables might be the way to go? It’s a darn handy module - there’s a thread on it here too. Fresh Variables are parsed before path.php globsl variables I think.

  • #3 / Jun 15, 2008 4:04am

    Ingmar

    29245 posts

    I second Luke’s suggestion. Or you can use a variable defined in path.php, which is parsed rather early on as well. But do give Fresh variables a try, highly recommended.

  • #4 / Jun 15, 2008 12:49pm

    S. Lee Ware

    39 posts

    Luke and Ingmar - thanks for the suggestion, I am looking into the Fresh Variables module to see if it can accomplish what I want.

  • #5 / Jun 16, 2008 2:15pm

    S. Lee Ware

    39 posts

    Unfortunately, no ... Fresh Variables does not do what I am looking for.  Basically, I want to set virtually all the content of a page based on the user’s member group.

    To do this, I need, very early in the page parsing process, to have access (in variable form) to the user’s member group info.

    I can’t use Fresh Variables because, though they are parsed early, any tags in them won’t be (same as path.php global variables).

    And even setting up an intermediate template to pass the information on to an embedded template won’t work because embeds are parsed just before the standard global variables.

    Stated simply - I need dynamic member group info early in the parse order, and don’t know where to get it except in the standard global variables like {group_id} or {group_title}.

    Does anyone know of a way to get this info early in the parse order in some other way (custom query, or php, or anything?)

  • #6 / Jun 16, 2008 2:42pm

    Ingmar

    29245 posts

    Stated simply - I need dynamic member group info early in the parse order, and don’t know where to get it except in the standard global variables like {group_id} or {group_title}.

    Try PHP, using something like

    <?php global $SESS; echo $SESS->userdata['group_id']; ?>

    on input.

  • #7 / Jun 16, 2008 3:07pm

    S. Lee Ware

    39 posts

    Ingmar - you are absolutely wondrous in your knowledge and the generosity with which you share it - this is a perfect solution - I think this simple line of code is going to totally change my day from one of hair pulling and gnashing teeth to one of serene smiles and awesome results.

    I needed a slightly different PHP line for my purposes:

    <?php global $SESS; echo $SESS->userdata['group_title']; ?>

    I have done a simple test to see if this indeed solves my parse order problems, and it does with flying colors.

    Thanks again Ingmar - though I doubt it could happen, I hope to be able to help you in like measure someday (perhaps if you ever have questions about ceramics or gardening or secular ethics, I can offer a bit more expertise!)

  • #8 / Jun 16, 2008 3:13pm

    Ingmar

    29245 posts

    I think this simple line of code is going to totally change my day from one of hair pulling and gnashing teeth to one of serene smiles and awesome results.

    Sounds like a good day, then 😊

    I have done a simple test to see if this indeed solves my parse order problems, and it does with flying colors.

    Yes, this is an array that contains a handful of other variables as well. You can read up on them, if you’re so inclined, in the docs (where else?)

    And I’m glad to be able to help, so no worries.

  • #9 / Jun 16, 2008 3:44pm

    S. Lee Ware

    39 posts

    Ingmar - thanks for that link, I had never thought to look in the development docs.

    I was hoping that using the PHP you suggested would be the key to harnessing the Fresh Variables module to create a side-wide session variable, but when I set up a new Fresh Variable, the following code didn’t work:

    {exp:query sql="SELECT entry_id FROM exp_weblog_titles WHERE title = '<?php global $SESS; echo $SESS->userdata['group_title']; ?>'"}
    {entry_id}
    {/exp:query}

    When I create a dynamically assigned variable to use in an individual template, I can use

    {assign_variable:group="<?php global $SESS; echo $SESS->userdata['group_title']; ?>"}

    to get the group title and name it “group”.

    Then, If I set a query to feed an exp:weblog:entries tag the proper entry_id

    {exp:query sql="SELECT entry_id FROM exp_weblog_titles WHERE title = '{group}'"}

    it works.  But combining these two steps into a Fresh Variable doesn’t work, at least in the way I have the code above.

    Any suggestions?

    (edited code to make more sense)

  • #10 / Jun 16, 2008 4:43pm

    S. Lee Ware

    39 posts

    To clarify, I am attempting to set up site functionality and displayed content based on the member group of the currently logged-in user.  To do this, I have a weblog called “companies”, where each entry title is a company name.  For each company, there is also a user group named exactly the same thing (the company name).  Therefore, all the content displayed to a user within a user group is pulled via relationships / reverse relationships through the entry with the entry title to match the group_title.

    This keeps things from being determined by URI (which was not secure for my purposes, since I could not assign group access at the individual entry level), and I do not want to build templates for each company.

    Is that clearer, or less clear?

  • #11 / Jun 18, 2008 11:28am

    Luke Stevens

    80 posts

    Beyond me I’m afraid, and while this suggestion is probably more annoying than anything given all the work you’ve done, Leevi has an extension which allows you to assign users (not groups) to an entry. As mentioned that’s users, not groups, though, so I don’t know if it’s particularly useful but if you have $ you might be able to work something out with Leevi, dunno. Just fwiw!

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

ExpressionEngine News!

#eecms, #events, #releases