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.

If/Else Statement Help

August 22, 2011 11:30pm

Subscribe [3]
  • #1 / Aug 22, 2011 11:30pm

    Color-ize

    27 posts

    v2.2.2 - Build: date 20110801

    I have setup a template that allows me to have three columns or two columns based on if the user has actually put something in the “Side Content” box, but when I do the if else statement it isn’t working.

    Here is how I have it setup:
    {exp:channel:entries category="{segment_2_category_id}” dynamic=“no” limit=“1” orderby=“title” sort=“asc”}
          {if "{side_content}”==”“}
              {embed="about/two_column"}
          {else}
              {embed="about/three_column"}
          {/if}
            {/exp:channel:entries}

    Is it because I am pulling the pages by Category so I can use single channels for each department they cover?

    Any suggestions?

    Thank you!
    Seth

    Moved to Community Help forum by Moderator

  • #2 / Aug 23, 2011 12:19am

    Color-ize

    27 posts

    In part it had a wrong syntax. It should be: {if:else}.

    Whoops.


    Still isn’t working (after reviewing the coding, must be getting late, I’m revisiting everything I think I have working and it isn’t #$%$# *angry fist inserted here*!)

  • #3 / Aug 23, 2011 12:36am

    Color-ize

    27 posts

    Ok, so get this.
    I had to change it so it automatically embedded the 3 column layout, then when it loaded the three column layout if it had the field populated with content it checked it and would render the code as directed. The catch, I had to have the content placed in single quotes for the name of the field I was checking for content, with the content being in double quotes… Whatever, it works, I don’t know why, but it does: here was my final code:

    {exp:channel:entries category="{segment_2_category_id}" dynamic="no" limit="1" orderby="title" sort="asc"}
        {if '{side_content}' != ""}
            <div class="right_3_column">
              {side_content}
            </div>
            <div class="center_3_column">
                    <h3>{title}</h3>
    <p>                {content}<br />
            </div><br />
        {if:else}<br />
                    {embed="about/two_column"}<br />
        {/if}<br />
    {/exp:channel:entries}

  • #4 / Aug 23, 2011 2:34am

    Dave @ Exp:resso

    465 posts

    Assuming {side_content} is a custom field, you can usually just use {if side_content} 😊 Or if that doesn’t work {if side_content != ''}

  • #5 / Aug 23, 2011 2:49am

    Color-ize

    27 posts

    Hey thanks Dave! That’s a helpful tidbit I’ll have to keep under my belt!

    I ran into a new issue with this. Now it is displaying them in alphabetical order, whether I want them to be pulled onto the page or not, so now I’m onto my next issue.

    For an explanation, I have a page I want to display different content based on the Category you are wanting to look at in one of 26 different Channels. There are a total of 63 different categories strung out in the 26 different channels. I want it to do the same as above with all the different categories channels based on if they input side content on their pages. Well obviously I have 26 different if then statements on the same page, but now only one is showing that isn’t even referenced in the url…so I’m stuck for the night.

    If anyone wants to analyze this code, they can tell me what stupid thing I’m doing wrong. I’m too tired at this point to figure it out.

    {exp:channel:entries category="{segment_2_category_id}" dynamic="no" limit="1" sort="asc" orderby="title"}
        {if '{assessor_side_content}' != ""}
            <div class="right_3_column">
              {assessor_side_content}
            </div>
            <div class="center_3_column">
                    {embed="about/two_column"}
            </div>
        {if:elseif '{auditor_side_content}' != ""}
            <div class="right_3_column">
              {auditor_side_content}
            </div>
            <div class="center_3_column">
                    {embed="about/two_column"}
            </div>
        {if:elseif '{board_and_commissions_side_conte}' != ""}
            <div class="right_3_column">
              {board_and_commissions_side_conte}
            </div>
            <div class="center_3_column">
                    {embed="about/two_column"}
            </div>
        {if:elseif '{board_of_supervisors_side_conten}' != ""}
            <div class="right_3_column">
              {board_of_supervisors_side_conten}
            </div>
            <div class="center_3_column">
                    {embed="about/two_column"}
            </div>
        {if:else}
                    <h3>{title}</h3>
    <p>                {content}<br />
                    {auditor_content}<br />
                    {board_and_commissions_content}<br />
                    {board_of_supervisors_content}<br />
                    {buildings_and_grounds_content}<br />
                    {communications_center_content}<br />
                    {communities_content}<br />
                    {community_services_content}<br />
                    {conservation_director}<br />
                    {contact_content}<br />
                    {county_attorney_content}<br />
        {/if}<br />
    {/exp:channel:entries}

    That’s the general gist anyway.
    Sooo, if anyone can figure out my ramblings and thinks they can untangle my mess and help out, I’d be grateful!!

    Anyway, my mind is going into shutdown, thanks for tuning in…good night!
    Seth

  • #6 / Aug 23, 2011 2:57am

    Dave @ Exp:resso

    465 posts

    Hi Seth, a few notes:

    Well is the category in the url? If so then you’d want to remove dynamic=“no” and category=”“.

    Not sure what {segment_2_category_id} is…?

    Only one is showing since you have limit=“1”

    I’m 95% sure your if:else syntax with the quote marks is unnecessary - see my last post.

    Are you sure you need 26 channels? Do you have 26 different content types? If not you should have probably used nested categories.

    EDIT - I’m assuming you’re wanting to display a list of entries rather than a single entry

  • #7 / Aug 23, 2011 10:44am

    Color-ize

    27 posts

    Hi Dave,
    That helped - first thing this morning. I removed the dynamic=“no” and voila it showed up correctly! So thank you! I’m sure your right with the if:else syntax and the quotes, but it is functioning and I don’t have time to mess with the code if I don’t have to, so I will probably leave it for now. Thanks for the help 😊

    As for the {segment_2_category_id} it is from an extension that helps specify the urls based on specific segments. It is called: Low Seg2Cat. It is found here: http://gotolow.com/addons/low-seg2cat/docs

    Which I’m glad I had to go look up what it was again, because that was where my real problem was. I turned back on the dynamic=“no” and it works. When I went into settings for that extension I had to specify to use it with all the other channels.

    Next - I need the 26 channels for the 26 departments. They all have similar content, and you’re probably right it’s overkill. Butttt, I will have one user from each of the 26 departments that only will have access to that channel for adding content to the website.

    I also only want one showing on each page. Maybe my logic is off, but it was how I could put it together in a feasible time frame. There are three that I want to show more than one on a page, but that’s it.

    Thank you for your input! It helped clear my head when I got here, and it is finally functioning like I want it.

  • #8 / Aug 23, 2011 10:46am

    Sue Crocker

    26054 posts

    Thanks for the assist, Dave.

    Color-ize, we can’t provide direct support for using Seg2Cat, so moving this over to the Community Help forum for additional community support.

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

ExpressionEngine News!

#eecms, #events, #releases