section show and ezselection

Author Message

laurent le cadet

Sunday 15 October 2006 5:11:02 am

Hi,

I can't find something to check if an ezselection attribute (multichoices) has content or not to use a "section show".

I tryed almost everything (has_content, is_empty|not, data_int)...whithout success :(

Any hint ?

Regards.

Laurent

Claudia Kosny

Sunday 15 October 2006 7:50:52 am

Hi Laurent

As far as I remember the content of an ezselection is stored in data_test to allow for multiple selects so you might try that.
According to the documentation for selection, 'The ".content" of an ezcontentobjectattribute object using this datatype returns an array of the identification numbers (as strings) of the selected options.' So another idea might be to just check for $attribute.content which should be an empty array if nothing is selected.

Greetings from Luxembourg

Claudia

laurent le cadet

Sunday 15 October 2006 7:59:06 am

Hi Claudia,

Yes, it returned an array. But how do you check it's empty or not ?

...

Claudia Kosny

Sunday 15 October 2006 8:24:59 am

Just count the elements - if the count is zero the array is empty.

{def $foo = array()}
{if $foo|count()|eq(0)}
 the array is empty
{else}
 the array is not empty
{/if}

Actually most of the if condition is not strictly necessary:
{if $foo} should evaluate to true if the array contains something and to false otherwise
{if $foo|count()} should evaluate to true if the array contains something and to false otherwise
but as this is not clearly mentioned in the documentation (or I have not found it), I would not rely on such shortcuts.

Greetings from Luxembourg

Claudia

laurent le cadet

Monday 16 October 2006 12:36:36 am

Claudia,

I'm using a 3.6.4 so i tryed something based on your codelike this

{section show=$node.object.data_map.langues.attribute.content|count()|gt(0)}...{/section}

But if there is a least nothing or one item selected, {$node.object.data_map.langues.attribute.content|count()} is still equal to 1 (!!!?)

If I have 2 options selected it's equal to 2 which is more logical...

Stuck.

Claudia Kosny

Monday 16 October 2006 1:34:33 pm

Hi Laurent

Sorry, I had totally forgotten that an ezselection without anything selected still returns an array with one entry (whose value is an empty string).

Seeing this, you either should use data_text or sort_key_string for your show condition. If you want to use the content of the attribute you have to check whether the first array entry is an empty string or contains a number. I don't know which method is better so just use the one you like most.

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.