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 display of category custom fields

July 04, 2011 1:38am

Subscribe [4]
  • #1 / Jul 04, 2011 1:38am

    Dane C

    23 posts

    I just rearranged the infrastructure of the site I’m building to make things more efficient, and moved the custom fields from one of my channels into custom category fields.  The problem is my conditionals no longer work.  It works with the standard category fields, just not the custom ones.

    This is my code:

    {categories}
    {if web_site_url}<a href="http://{web_site_url}">/images/icons/home.png</a>{/if}
    {if facebook_url}<a href="http://{facebook_url}">/images/icons/Facebook_64.png</a>{/if}
    {/categories}

    If I remove the if statement, it works, but with the if statement in there, nothing displays.  I also tried {if web_site_url != ""}, to no avail.

    I found an old thread about this same thing, and the person was directed to submit a bug report.  That thread was several years old and closed - hopefully there’s a solution?

  • #2 / Jul 04, 2011 3:39am

    Dane C

    23 posts

    I thought I might have come up with a workaround, but it also didn’t work.  I put “0” into any field that didn’t have data, and then changed my if statement to {if web_site_url != "0"} ... when I do that, it displays the link whether the data is 0 or otherwise.  So the if statement still doesn’t work, but in this case it displays the code.  Not sure if that’s helpful.

  • #3 / Jul 04, 2011 6:29am

    Matt:P

    277 posts

    Hi Dane

    Your if statements are correct, could you explain why they’re in the Categories tag pair?

  • #4 / Jul 04, 2011 10:53am

    Dane C

    23 posts

    Because the data is being pulled from custom fields assigned to my categories.

    https://support.ellislab.com/bugs/detail/12373/

    This is the exact same problem I’m having - except according to this, the bug should be fixed.  There’s a temporary fix recommended in there, but the file has changed since that time.

  • #5 / Jul 04, 2011 11:50am

    Dane C

    23 posts

    Well, another update.

    I was using 2.1.3, and I just updated to 2.2.1.  The bug I mentioned above should have been fixed long before 2.1.3, but still upgraded for good measure.

    Now the conditional statement breaks the categories tag pair completely.  The moment I put any kind of {if} statement inside of the {categories} tag pair, it just displays the code {categories} {/categories} right on the page.  If I remove the {if} statement, it works again.

  • #6 / Jul 04, 2011 12:04pm

    Matt:P

    277 posts

    Hi Dane

    Do you have your code inside an Entries tag? see below… (if you do could you show us the whole Channel Entries tag or the whole Channel Categories tag/code please?)

  • #7 / Jul 04, 2011 4:25pm

    Dane C

    23 posts

    It is, and sure:

    {exp:channel:entries channel="conventions" show_future_entries="yes"}
    {categories}
    {if web_site_url}<a href="http://{web_site_url}">/images/icons/home.png</a>{/if}
    {if facebook_url}<a href="http://{facebook_url}">/images/icons/Facebook_64.png</a>{/if}
    {/categories}
    {/exp:channel:entries}

    For some context, the site lists yearly conventions around the country, and basically I create a category for each convention so I can put blog/news posts, images, videos, dates and venues, etc into channels and just assign them to the category.  I started out storing this information in a separate channel but ran into some conflicts - then it hit me - this information is universal to the convention, so it can be stored in custom fields in the category rather than needing a separate channel (hope that makes sense!)  It’s way more efficient that way.  The problem is my conditionals worked when the data was in a channel, and they’re not since I moved them to the category fields.

    I’ve even tried stripping the template to just that code, and it’s the same.  Without the conditional, it displays the custom fields just fine, but the moment I add the conditional, it displays {categories}{/categories}

  • #8 / Jul 05, 2011 4:49pm

    Kevin Smith

    4784 posts

    Hey Dane,

    Be on the lookout for an email from me. Let’s see what this looks like first-hand.

  • #9 / Jul 11, 2011 5:27pm

    Kevin Smith

    4784 posts

    Dane, maybe I’m missing something, but the URL you sent me appears to be displaying the category links just fine. When I remove them from the template, indeed nothing shows. But if I leave them just as you have them in the template, I see the link icons for the website, Facebook, etc…

    Did you figure out the problem on your own? Are you still experiencing the issue on your end?

  • #10 / Jul 11, 2011 6:56pm

    Dane C

    23 posts

    Uhh… yeah, it was working when I got up the next morning.  I meant to jump on here and thank you for fixing it, assuming you’d done it in the morning before I woke up, but forgot!

    Well, now I’m confused.  I swear to you it was broken and I tried a ton of things to try to get it working - then with no more work on my part, the next morning it was fine.

  • #11 / Jul 12, 2011 4:53pm

    Kevin Smith

    4784 posts

    Well… I suppose that’s good, but it would leave me wondering what caused the issue in the first place. I’ll close this thread out since it looks to be a non-issue now. If it rears its head again, please just open up a new thread by clicking the button below. We’ll go from there.

    Glad it’s working now, Dane!

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

ExpressionEngine News!

#eecms, #events, #releases