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.

eZ debug

Timing: Jan 18 2025 16:16:28
Script start
Timing: Jan 18 2025 16:16:28
Module start 'layout'
Timing: Jan 18 2025 16:16:28
Module start 'content'
Timing: Jan 18 2025 16:16:30
Module end 'content'
Timing: Jan 18 2025 16:16:30
Script end

Main resources:

Total runtime1.4389 sec
Peak memory usage4,096.0000 KB
Database Queries66

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0091 587.9141152.6250
Module start 'layout' 0.00910.0049 740.539139.4453
Module start 'content' 0.01401.4233 779.9844539.0234
Module end 'content' 1.43730.0015 1,319.007816.1641
Script end 1.4388  1,335.1719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00480.3369160.0003
Check MTime0.00250.1726160.0002
Mysql Total
Database connection0.00100.067310.0010
Mysqli_queries1.371695.3232660.0208
Looping result0.00060.0430640.0000
Template Total1.363394.720.6816
Template load0.00440.305120.0022
Template processing1.358994.440320.6794
Template load and register function0.00010.006710.0001
states
state_id_array0.00170.116410.0017
state_identifier_array0.00330.229620.0017
Override
Cache load0.00400.2779430.0001
Sytem overhead
Fetch class attribute can translate value0.00060.038920.0003
Fetch class attribute name0.00110.074170.0002
XML
Image XML parsing0.00050.031620.0002
class_abstraction
Instantiating content class attribute0.00000.001290.0000
General
dbfile0.00070.0480160.0000
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs