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.

Simple conditional with user defined global

July 15, 2011 5:13am

Subscribe [2]
  • #1 / Jul 15, 2011 5:13am

    pod

    8 posts

    Hi

    We have been reading about parse order and alike but are still head scratching why the below doesn’t work - unless the //{includeitem} is there. Clearly we don’t want to output our variable just to be able to use it.

    We tried the below in a snippet also without success. I guess we have some fundamental things wrong with the approach(es) of the code below. All suggestions welcome.

    Thanks
    Pod

    <?php
    $groupid = $this->EE->session->userdata['group_id'];
    ?>
    {exp:query sql="SELECT group_title FROM exp_member_groups WHERE group_id = '<?php echo $groupid;?>' "}
    <div id="pageMenu">
       {exp:channel:categories channel="page_heading"}
            <a href="#">{category_name}</a>
        {exp:channel:entries channel="page_heading" disable="member_data|trackbacks" category="{category_id}" uncategorized_entries="no"}
            {preload_replace:includeitem="{exp:StringSearch needle='{group_title}' haystack='{access}' length='7'}"}
            //{includeitem}
            {if '{includeitem}' == '1'}
                <a href="#">{title}</a>
            {/if}
        {/exp:channel:entries}
        {/exp:channel:categories}
    </div>
    {/exp:query}
  • #2 / Jul 15, 2011 4:27pm

    Kevin Smith

    4784 posts

    It looks to me like there are a lot of parse order issues going on here. For example, you have a plugin’s output being used as a preload_replace variable when plugins are parsed after preload_replace. I’m actually surprised it’s working at all.

    Also, and this is unrelated, but it’s the first thing that caught my eye and would help simplify your template a lot. I see the PHP and Query Tag is being used to retrieve the group title. Is there some reason you had to do this instead of just using the {group_title} Global Variable? If it was an attempt to get around the parse order issue (since Global Variables are parsed rather late), you might want to at least use a different variable name as output by the Query Tag.

    Could you enlighten me about what this block of code is trying to achieve?

  • #3 / Jul 18, 2011 12:40pm

    pod

    8 posts

    Thanks, understanding the parse order has helped figure the first point.

    The PHP was added out of desperation since {group_title} wasn’t working either.

    We are on a learning curve so have been hacking around with solutions - hence the odd code!

    Thats probably all we wanted from this post. We appreciate the input.

    Regards
    Pod

  • #4 / Jul 20, 2011 5:27pm

    Sue Crocker

    26054 posts

    Glad Kevin was able to help. If anything else comes up, please do let us know in a new thread..

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

ExpressionEngine News!

#eecms, #events, #releases