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.

show_empty="yes" doesn’t show anything under certain conditions

March 24, 2008 12:05pm

Subscribe [1]
  • #1 / Mar 24, 2008 12:05pm

    eexperience

    56 posts

    This problem is driving me a bit nuts. I’m working on a site where I select an area first and if an area category has been chosen it shows a list of all types of activities. This works but only as long as I select an area where I have entries.

    My most basic problem is, why doesn’t the {if not_category_request} nor the {if category_request} show anything when I have a URL with a category ID that doesn’t have any entries? If I have no category ID in the URL or a category ID that contains entries everything works as expected.

    There must be some relationship behind the scenes that I’m not aware of.

    Thanks for the help,
    Timon

    <div id="navigation">
        {exp:weblog:entries limit="1"}
            {if not_category_request}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="3"} {!-- Category Group "Area" --}
                    <a href="http://{path=">{category_name}</a>
                    no request {!-- output for testing purposes --}
                {/exp:weblog:categories}
            {/if}
            {if category_request}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="2"} {!-- Category Group "Type" --}
                    <a href="http://{site_url}{site_index}/{segment_1}/{segment_2}/{segment_3}/tag/{category_name}">{category_name}</a>
                {/exp:weblog:categories}
                category requested {!-- output for testing purposes --}
                {exp:subcategories}
                     <strong><a href="http://{path=">{category_name}</a></strong>
    
                {/exp:subcategories}
            {/if}
        {/exp:weblog:entries}
    </div>

    Mod Edit: Moved to the How To forum.

  • #2 / Mar 24, 2008 12:25pm

    Robin Sowell

    13255 posts

    I expect it’s the nesting, but I’m a little fuzzy on what you’re doing.  And I suspect it could be done differently.

    Can you link us to a page where we can see it in action?  Think I’d get the gist if I could see a page where it works and one where it doesn’t.

  • #3 / Mar 24, 2008 12:35pm

    eexperience

    56 posts

    Hi Robin,
    I’ve sent you a PM with the URLS.

    Thanks for your help,
    Timon

  • #4 / Mar 24, 2008 12:42pm

    eexperience

    56 posts

    I have updated the HTML a bit, to bring more clarity to it. But I haven’t changed any EE code.

    <div id="navigation">
        {exp:weblog:entries weblog="eintraege" limit="1"}
            {if not_category_request}
                no category request {!-- output for testing purposes --}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="3"} {!-- Category Group "Area" --}
                    <a href="http://{path=">{category_name}</a>
                {/exp:weblog:categories}
            {/if}
            {if category_request}
                category requested {!-- output for testing purposes --}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="2"} {!-- Category Group "Typ" --}
                    <a href="http://{site_url}{site_index}/{segment_1}/{segment_2}/{segment_3}/tag/{category_name}">{category_name}</a>
                {/exp:weblog:categories}
                Subcategories: 
                {exp:subcategories}
                     <strong><a href="http://{path=">{category_name}</a></strong>
    
                {/exp:subcategories}
            {/if}
        {/exp:weblog:entries}
    </div>
  • #5 / Mar 24, 2008 12:57pm

    Robin Sowell

    13255 posts

    OK- took a look.  The way I’d approach it is to use php parsed on input to determine whether it’s a category page or not- and use php conditionals to determine which would show.  It would be leaner- no need for the weblog tag at all- and avoid the nesting entirely.

    I can help you out with the php if that will work.  Will it?

  • #6 / Mar 24, 2008 1:01pm

    eexperience

    56 posts

    Hi Robin,
    any help is appreciated since I don’t know much about PHP and I’m using EE to work my way around not knowing PHP.

    So besides that a PHP approach would produce leaner code, is there anything wrong with my syntax or why isn’t it working?

  • #7 / Mar 24, 2008 1:11pm

    Robin Sowell

    13255 posts

    If I had to bet- it’s related to parse order and your nesting.  One thing you could try that would eliminate that- move the contents inside the conditionals out to other templates- then in the conditionals, do an embed.  But that adds a wee bit more weight and just isn’t necessary as far as I see.  I’d go php on this one.

    That said?  You can give it a try- I’m betting it will work that way, as it basically eliminate parse order and nesting complexities.

  • #8 / Mar 24, 2008 1:19pm

    eexperience

    56 posts

    Thanks, I will have to try that. As you know this is already the second time that I bumped into this complexity issue (http://ellislab.com/forums/viewthread/74577/). Will this be something that gets addressed in future releases? Because I really depend on such conditionals to do more complex things.

  • #9 / Mar 24, 2008 1:24pm

    Robin Sowell

    13255 posts

    In truth- I’m not sure what 2.0 holds in store.  The major problems here have to do with the way EE conditionals work and that you’re nesting tags based on those conditionals.  Which is something I try to avoid.

    That said?  Now is the time to add feature requests for things you know would be handy!

  • #10 / Mar 24, 2008 1:27pm

    eexperience

    56 posts

    Ok, I’ll add a feature request for improved nesting of conditionals.

    Could you let me know how to check in PHP if a category has been set? I would really appreciate this, since I heavily depend on whether or not a category has been requested.

    Thanks for the ongoing support,
    Timon

  • #11 / Mar 24, 2008 1:42pm

    Robin Sowell

    13255 posts

    Sure- depends on whether you need to know the category- which this will give you:

    <?php
    global $IN;
    $cat = (preg_match("#(^|\/)C(\d+)#", $IN->QSTR, $match)) ? $match['2'] : 'no';
    ?>
    So $cat would either be a number- if it's a cat page, or 'no' if it's not.  Parse it on input, then use conditionals to determine what happens:
    
    <?php
    if ($cat == 'no') {
    ?>
    no category request {!-- output for testing purposes --}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="3"} {!-- Category Group "Area" --}
                    <a href="http://{path=">{category_name}</a>
                {/exp:weblog:categories}
    <?php } else { ?>
    
               category requested {!-- output for testing purposes --}
                {exp:weblog:categories show_empty="yes" style="nested" category_group="2"} {!-- Category Group "Typ" --}
                    <a href="http://{site_url}{site_index}/{segment_1}/{segment_2}/{segment_3}/tag/{category_name}">{category_name}</a>
                {/exp:weblog:categories}
                Subcategories:
                {exp:subcategories}
                     <strong><a href="http://{path=">{category_name}</a></strong>
    
                {/exp:subcategories}
    
    
    <?php } ?>

    Untested, but the right general idea.

  • #12 / Mar 24, 2008 1:45pm

    eexperience

    56 posts

    Thanks Robin, I really appreciate the high quality of your support. For me this is one of the reasons why I’m really happy to use a commercial product compared to a free product.

  • #13 / Mar 24, 2008 2:11pm

    eexperience

    56 posts

    Hi Robin,
    I forgot to allow PHP in templates, but after that your code worked out of the box.

    The only problem is the problem itself still persists. So even with the surrounding PHP-code getting parsed on the input stage the category tree doesn’t show up if the URL contains an empty category.

  • #14 / Mar 25, 2008 7:45am

    eexperience

    56 posts

    Is this now an official bug?

  • #15 / Mar 25, 2008 12:54pm

    Robin Sowell

    13255 posts

    Hm- works on mine w/php parsed on input.  I’d add in the weblog parameter just in case- I did for testing since I have more than one weblog- in which case it’s required.

    Then- do a quick reduction test.  Pull out everything- then just make sure each category tag works.  In other words- nothing but the cat tags like:

    no category request {!-- output for testing purposes --}
    
               
    {exp:weblog:categories show_empty="yes" style="nested" category_group="3"} {!-- Category Group "Area" --}
    <a href="http://{path=">{category_name}</a>
    {/exp:weblog:categories}
    <hr>
    
    category requested {!-- output for testing purposes --}
    
    {exp:weblog:categories show_empty="yes" style="nested" category_group="2"} {!-- Category Group "Typ" --}
    <a href="http://{site_url}{site_index}/{segment_1}/{segment_2}/{segment_3}/tag/{category_name}">{category_name}</a>
    {/exp:weblog:categories}

    Just to make sure both show up ok otherwise.  Like I say- works on my install, so I think it’s something odd- cat group is off, weblog is required- something like that.

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

ExpressionEngine News!

#eecms, #events, #releases