Test for Single Choice

Author Message

David Jones

Friday 15 September 2006 3:31:38 am

I've got a single choice field in a defined class news.

The two optios are Yes / No.

I want to do something if yes and do somthing else if no. But I don't seem to be able to get the test to work.

This is the code I have

	{foreach $node.children as $newsFeatured}	
	    {if eq($newsFeatured.object.data_map.featured,'Yes')}
               do something
           {/if}
         {/foreach}

I've also tried:

{if eq($newsFeatured.object.data_map.featured,Yes)}
{if eq($newsFeatured.object.data_map.featured,'yes')}
{if eq($newsFeatured.object.data_map.featured,yes)}

How do I do this test?

Thanks

Claudia Kosny

Friday 15 September 2006 3:53:20 am

Hello David

Have a look at the attribute in question with
{$newsFeatured.object.data_map.featured|attribute('show', 2)}

There you will probably see that you are interested in the content of this attribute so fetch this one and inspect it the same way. There you can see what you have to compare with, most likely it is the number of the selected option. If you used a selectbox, the content contains an array where you have to fetch the first item if I remeber correctly.

Greetings from Luxembourg

Claudia

David Jones

Friday 15 September 2006 5:57:25 am

Thanks for your help claudia

{$newsFeatured.object.data_map.featured.content|attribute('show', 2)}

Outputs

Attribute 	Type 	Value
0 	           string 	1
Attribute 	Type 	Value
0 	           string 	0
Attribute 	Type 	Value
0 	           string 	1

So i've tried

{if eq($newsFeatured.object.data_map.featured,0)}
{if eq($newsFeatured.object.data_map.featured.content,0)}
{if eq($newsFeatured.object.data_map.featured.content|attribute,0)}

Interestingly the last one outputs all 3. The others have no output.

I just want to output the one with value 0.

Thanks again

Claudia Kosny

Friday 15 September 2006 8:00:50 am

Hi David

Does this
{$newsFeatured.object.data_map.featured.content|attribute('show', 2)}
output all 3 lines or just one for each time you call it up?
I hope it is the latter as otherwise I am not sure what datatype you use.

I will assumethat the output is just one of these lines.

Attribute       Type    Value
0                 string       1

This means that your attribute has an array as content which has one entry. This entry has the key 0, the value is of type string and has the content 1 (or 0 in one of your other lines).
This number is the key of your selection (basically the number of the entry in the selection counted zero based). If you would have a checkbox 1 would mean that it is selected, 0 not selected (although in case you would not have an array as content of the attribute but the number itself)

So to properly compare you have to access the first entry of this array. You can do that like this:

{$newsFeatured.object.data_map.featured.content[0]}

This is what you have to compare with.

Greetings

Claudia

David Jones

Friday 15 September 2006 8:57:25 am

Thanks again,

That was spot on, problem solved

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 18:42:46
Script start
Timing: Jan 18 2025 18:42:46
Module start 'layout'
Timing: Jan 18 2025 18:42:46
Module start 'content'
Timing: Jan 18 2025 18:42:47
Module end 'content'
Timing: Jan 18 2025 18:42:47
Script end

Main resources:

Total runtime0.7886 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 587.9063152.6250
Module start 'layout' 0.00520.0026 740.531339.4297
Module start 'content' 0.00780.7793 779.9609503.1328
Module end 'content' 0.78710.0015 1,283.093812.1875
Script end 0.7885  1,295.2813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4225160.0002
Check MTime0.00150.1952160.0001
Mysql Total
Database connection0.00070.087510.0007
Mysqli_queries0.722691.6385630.0115
Looping result0.00060.0759610.0000
Template Total0.747694.820.3738
Template load0.00210.268220.0011
Template processing0.745594.538820.3728
Template load and register function0.00030.033310.0003
states
state_id_array0.00180.224610.0018
state_identifier_array0.00350.440520.0017
Override
Cache load0.00200.2587510.0000
Sytem overhead
Fetch class attribute can translate value0.00050.061120.0002
Fetch class attribute name0.00170.221650.0003
XML
Image XML parsing0.00030.036020.0001
class_abstraction
Instantiating content class attribute0.00000.002150.0000
General
dbfile0.00070.0835100.0001
String conversion0.00000.000840.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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs