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.

Conditional Errors

July 02, 2012 3:41pm

Subscribe [3]
  • #1 / Jul 02, 2012 3:41pm

    Phil Ecker

    78 posts

    I have a EE site and I’m trying to use conditionals to create output specific to separate groups. I have a “search” snippet that has the following code.

    <div id="search">
    {exp:search:simple_form search_in="entries" no_result_page="search/no-results/" result_page="search/results/" show_expired="yes" show_future_entries="yes" channel="not spotlight|exceptional_service|ideas|promo_entry" status="not private"}
    <div class="input-wrapper">
    <input type="text" name="keywords" autocomplete="off" id="keywords" value="Begin Searching…" /></div>
            <input type="submit" value="" class="submit" />
    {/exp:search:simple_form}
    </div>

    I’ve tried the following:

    <div id="search">
    {if username == "philecker"}
    {exp:search:simple_form search_in="entries" no_result_page="search/no-results/" result_page="search/results/" show_expired="yes" show_future_entries="yes" channel="not spotlight|exceptional_service|ideas|promo_entry"}
    {if:else}
    {exp:search:simple_form search_in="entries" no_result_page="search/no-results/" result_page="search/results/" show_expired="yes" show_future_entries="yes" channel="not spotlight|exceptional_service|ideas|promo_entry" status="not private"}
    {/if}
    <div class="input-wrapper">
    <input type="text" name="keywords" autocomplete="off" id="keywords" value="Begin Searching…" /></div>
            <input type="submit" value="" class="submit" />
    {/exp:search:simple_form}
    </div>

    And

    <div id="search">
    {exp:search:simple_form search_in="entries" no_result_page="search/no-results/" result_page="search/results/" show_expired="yes" show_future_entries="yes" {if username == "philecker"}{if:else}status="not private"{/if} channel="not spotlight|exceptional_service|ideas|promo_entry"}
    <div class="input-wrapper">
    <input type="text" name="keywords" autocomplete="off" id="keywords" value="Begin Searching…" /></div>
            <input type="submit" value="" class="submit" />
    {/exp:search:simple_form}
    </div>

    Both give me errors like below.

    Parse error: syntax error, unexpected T_ENDIF in /var/www/html/teamnet/system/expressionengine/libraries/Functions.php(656) : eval()'d code on line 66

    I’m trying to get status=“not private” to display for one group and not another. Can I not use conditionals within simple search forms? Any help would be greatly appreciated.

  • #2 / Jul 02, 2012 4:03pm

    Max Lazar

    341 posts

    {if:else} is Advanced Conditionals

    Advanced Conditionals are evaluated after all EE tags are parsed.

    so, try to replace it this way:

    <div id="search">
    {exp:search:simple_form search_in="entries" no_result_page="search/no-results/" result_page="search/results/" show_expired="yes" show_future_entries="yes" {if username == "philecker"}{/if}{if username != "philecker"}status="not private"{/if} channel="not spotlight|exceptional_service|ideas|promo_entry"}
    <div class="input-wrapper">
    <input type="text" name="keywords" autocomplete="off" id="keywords" value="Begin Searching…" /></div>
            <input type="submit" value="" class="submit" />
    {/exp:search:simple_form}
    </div>

     

  • #3 / Jul 02, 2012 4:06pm

    Phil Ecker

    78 posts

    I tried that and still get the same error, would it have anything to do with that being a Snippet? Plus, I really need to use a member_group and 4 member_id’s so would there be a way i could restructure things to use advanced conditionals?

  • #4 / Jul 02, 2012 4:13pm

    Max Lazar

    341 posts

    1. My example is correct. I just check it on my installation. So you need carefully check your template for any other IF’s
    2. Look on Switchee

  • #5 / Jul 03, 2012 3:24pm

    Shane Eckert

    7174 posts

    Hey Phil,

    Looks like you have gotten some great feedback here.

    I would just add to Max’s suggestion that you move from a snippet to an embed.

    Let us know how it goes.

    Cheers,

  • #6 / Jul 05, 2012 4:00pm

    Phil Ecker

    78 posts

    Thanks Max and Shane,

    I removed my search from the snippet, and switched to using an embeded template and everything is working GREAT now! Can’t thank you both enough.

  • #7 / Jul 05, 2012 4:01pm

    Shane Eckert

    7174 posts

    Hey Phil,

    Awesome! Glad we could help.

    If you need anything else, please just let me know by opening a new thread.

    Cheers,