Results 1 to 11 of 11

Thread: Problem when taxonomy value is zero

  1. #1
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Problem when taxonomy value is zero

    Hi,

    I am using taxonomy to select values from 0 to 5+

    I then output something like:

    Bedrooms = 4
    Bathrooms = 2

    My problem is if I select the value 0 I expect to output:

    Garages = 0

    But the 0 is missing, leaving me with:

    Garages = 0

    Is there a solution or workaround that will enable me to display a value of zero?

    Example can be seen here: http://cms-1.doublespark.eu/catalogue-properties.html

    Thanks in advance.

    Gary.

  2. #2
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Problem when taxonomy value is zero

    Rather use a numer field with min and max values. This is a much better idea, as I've already done a property catalog before.

    Taxonomy values are stored as their IDs not the name or alias, which will make it impossible to create a range filter, eg between 2-4 bedrooms.

  3. #3
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Re: Problem when taxonomy value is zero

    Thanks for the tip, appreciated!!

  4. #4
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Re: Problem when taxonomy value is zero

    Hi Thyon,

    I changed as suggested, now using a number field but still if I input "0" (zero) the number still does not display, in the ouput. If I change it to >=1 then it displays fine.

    See the first listing here http://cms-1.doublespark.eu/catalogue-properties.html

    Garage Spaces should display as x0

    The listing below it shows fine with a numeric value of 1.

    This is my template code:

    Code:
    <span class="garage_spaces">x<?php echo $entry['data']['garage_spaces']['value']; ?></span>
    and this is the output:

    Code:
    <span class="garage_spaces">x</span>
    I must be doing something wrong, but unsure what.

    Any further advice much appreciated.

    Cheers,

    Gary.

  5. #5
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Problem when taxonomy value is zero

    You're not doing anything wrong, but most clients don't want a field displayed unless its value is NON-NULL. If you look at the catalog_full.tpl file, you will notice that it checks if the value is zero before display. You can remove that check, change it to bypass if it's garage (or a list of fields) or simply create a completely custom template that will display even 0 as its value.

    To bypass the zero value check list of fields (bedrooms, garage) you can use this:
    Code:
    <?php if ((strlen($data['raw']) && !in_array($field, array('catalog_name','parentJumpTo'))) || in_array($field, array('bedrooms','garage'))): ?>

  6. #6
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Re: Problem when taxonomy value is zero

    Sorry Thyon, I tried the 1st way and removed the 0 check for garages etc - but it still did not display.

    I've stripped the template as fas as possible, and I'm left with this:

    Code:
    <?php if (count($this->entries)): ?>
    
    <div class="layout_full">
    <?php foreach ($this->entries as $entry): ?>
    <?php endforeach; ?>
    
    </div>
      <div class="layout_full">
        <div class="header"><?php echo $entry['data']['disp_address']['value']; ?>, <?php echo $entry['data']['postcode']['value']; ?></div>
        <div class="image"><?php echo $entry['data']['property_image']['value']; ?></div>
        <div class="summary_text">
          <div class="price">
    
    &pound;<?php echo $entry['data']['price']['value']; ?></p></div>
          <div class="property_description"><?php echo $entry['data']['property_description']['value']; ?></div>
        </div>
        <div class="icons">
          
    
    
            <span class="bedrooms">x<?php echo $entry['data']['bedrooms']['value']; ?></span>
            <span class="receptions">x<?php echo $entry['data']['receptions']['value']; ?></span>
            <span class="bathrooms">x<?php echo $entry['data']['bathrooms']['value']; ?></span>
            <span class="showers">x<?php echo $entry['data']['showers']['value']; ?></span>
            <span class="garage_spaces">x<?php echo $entry['data']['garage_spaces']['value']; ?></span>
          </p>
        </div>
    Must be something wrong in my code?

  7. #7
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Problem when taxonomy value is zero

    yes. just move the "endforeach" to AFTER all your manual placement code. Its looping through all the entries (even if its just 1) and then it reaches your code with a blank variable.

    Why not also look at the templates tutorial:
    http://dev.typolight.org/wiki/TutorialsCatalog

  8. #8
    User MacKP's Avatar
    Join Date
    06-19-09.
    Location
    Duisburg (Germany)
    Posts
    211

    Default Re: Problem when taxonomy value is zero

    Hi ,
    you can make it with an if else construkt i think.
    I made this normaly with images like that ->
    Code:
    <?php if($entry['data']['immo_bild']['meta']):?>
      <dd class="bild">
        ">[img]<?php echo $entry['data']['immo_bild']['meta']['0']['src']; ?>[/img]" width="200" height="100" />
      </dd>
    <?php else: ?>
    <?php endif;?>
    So I have an code when I have an image and nothing when no image is there...
    When you try the same like :
    Code:
    <span class="garage_spaces">x<?php if($entry['data']['garage_spaces']['value']):?><?php echo $entry['data']['garage_spaces']['value']; ?><?php else: ?>0<?php endif;?></span>
    I think that would give you the way you want. Normaly a Number of garages and when no garage is there you get an 0.

    regards
    Mediendepot Ruhr
    For real-time chat the (inofficial) Chatroom in IRC:
    -> irc.freenode.net #contao | irc.freenode.net #contao.de

  9. #9
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Re: Problem when taxonomy value is zero

    @Thyon - Thanks for pointing me in the right direction. This is my 1st time with Cat & CatExt, the fact I have got this far is testimony to your coding and documentation skills. Before starting I printed all three docs/tutorials and still refer to them every few mins. Not being very code orientated it is difficult to understand some of the code, but with help I am managing to "cut & paste" and achieve the desired results. I'm sure the php understanding will get better with time. Thanks again.

    @MacKP - Cheers, that works a treat, I now have Garages x0 :-)

  10. #10
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Problem when taxonomy value is zero

    If the value disappears because of a zero value, you can also FORCE the field to generate a number, but specifying the number format with a "0" as the parameter, e.g. 0 decimals.

  11. #11
    User
    Join Date
    06-19-09.
    Posts
    417

    Default Re: Problem when taxonomy value is zero

    Thanks Thyon, that will come in handy. Cheers.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •