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.

Using segment url tags inside fresh variables?

March 11, 2010 3:25pm

Subscribe [2]
  • #1 / Mar 11, 2010 3:25pm

    Joe Wolin

    206 posts

    I’m trying to create a fresh variable that uses {segment_2} as part of the variable.  It’s my understanding the segments are parsed before global variables so I would suspect this to work but instead it’s just pasing out the text ‘{segment_2}’

    I’ve tried going the php route and calling

    $seg1 = $IN->fetch_uri_segment('1');

    This seems to fail miserably.

    Can I not use segment variables inside my fresh variables?

  • #2 / Mar 11, 2010 3:48pm

    ender

    1644 posts

    not sure what you’re trying to achieve so I really don’t know if it suits your situation or not, but you could try the string plugin.  It runs at the same time as all the other template tags so global variables are available when setting string plugin variables.

  • #3 / Mar 11, 2010 3:54pm

    Joe Wolin

    206 posts

    Thanks ender,

    What I’m really trying to acheive is to grab some data in the url segment and pull a related bit of information.  I’m grabbing the screen_name as defined in the url_segment and want to get the member_id - so I can use it in various parameters. (and yes I’ve set it up so the screen_name contains only safe url characters)

    <?php
     global $DB;
     $query = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = '{segment_2}' ");
     $get_member_id = $query->row['member_id'];
    ?>

    I tried to put the above code into a fresh variable with no luck - apparently I don’t understand the parse order because I thought it should work.

    Will your string plugin be able to help me pull this code into an ee variable that I can use in my templates?

  • #4 / Mar 11, 2010 5:00pm

    ender

    1644 posts

    I think it could, yes.

    Set this PHP to parse on input (so that it runs before the template tags and thus can make its results available to the template tags):

    <?php
    global $DB, $IN, $SESS;
    $query = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = '{$IN->SEGS[2]}' "); // need to not use a template tag here for the segment
    if($query->numrows > 0) {
        $SESS->cache['string']['get_member_id'] = $query->result[0]['member_id'];
    } else {
        // probably want to do something here if they try to access something that doesn't exist
    }
    ?>

    later in the template (or even in an embedded template):

    {exp:string name="get_member_id"}
  • #5 / Mar 12, 2010 4:39pm

    ender

    1644 posts

    did you get the functionality you needed, one way or another?

  • #6 / Mar 12, 2010 4:42pm

    Joe Wolin

    206 posts

    Thanks ender for the follow up - your solution works when including the code in the template.  I’d still like to find a way to made the code a global variable so I don’t have to type this into every template.

    But I’ll run with it for now…

  • #7 / Mar 12, 2010 4:56pm

    ender

    1644 posts

    You might be able to put the PHP code into a fresh variable to cut down on the typing in each template, but the template will still need to have php parsing turned on.

  • #8 / Mar 12, 2010 6:16pm

    Joe Wolin

    206 posts

    ender, I tried this but it did not log the segment code - which is confusing since segment code is parsed before the global vars.

  • #9 / Mar 12, 2010 6:35pm

    ender

    1644 posts

    yeah, dunno there. to be honest I’ve tried fresh variables a couple times but it never made it to production code.

  • #10 / Mar 12, 2010 6:37pm

    Joe Wolin

    206 posts

    thanks for the help ender… btw a little off topic here but someone actually mentioned you might be a good contact for getting a modal-style login/registration box to work with ee.  I’d like to have fancybox popup so people can register on the site or login. 

    Is this something you’ve done?

  • #11 / Mar 12, 2010 6:58pm

    Gareth Davies

    491 posts

    Not tried it but wonder if Low Variables could handle what you need?

    http://loweblog.com/software/low-variables/

  • #12 / Mar 12, 2010 7:07pm

    Joe Wolin

    206 posts

    I’ll give this a look thanks Gareth

  • #13 / Mar 13, 2010 1:05pm

    ender

    1644 posts

    sure, I’ve done a bunch of ajax-y stuff with EE, just hit me up via PM (or skype during the week) and I can do a bit of consulting.

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

ExpressionEngine News!

#eecms, #events, #releases