Access selection datatype

Author Message

Robert Malevic

Saturday 07 June 2008 7:06:58 am

Hi,
Again a newbie question. I defined a FAQ class with a single choice selection datatype (category) which represent available categories:

selection category 1
selection category 2
...
selection category n

To display the FAQ's in different categories I tried the following code:

{for 0 to $option_count as $category_number}

<h4>DISPLAY THE CATEGORY STORED IN THE SELECTION ATTRIBUTE</h4>
    
{def $faqs=fetch( 'content', 'list', hash( 'parent_node_id', 399,
               'sort_by', array( 'attribute', true(), 'faq/question'),
               'class_filter_type', 'include',
               'class_filter_array', array( 'faq' ),
               'attribute_filter', array( array( 'faq/category',
               '=',
               $category_number ) ) ) )}
  
<ul class="faq-list">
    {foreach $faqs as $faq}  
    <li> <span class="fold-out">{$faq.data_map.question.content}</span>
        <div class="summary hide">
            {attribute_view_gui attribute=$faq.object.data_map.answer}
        </div>
    </li>
    {/foreach}
</ul>
{/for}

I have two questions:
1. How to determine the number of options available in the selection attribute ($option_count)?

2. How to extract the content of each available options to display in "<h4>DISPLAY THE CONTENT STORED IN THE SELECTION ATTRIBUTE</h4>"?

Thanks for your help!

Maxime Thomas

Sunday 10 August 2008 10:49:57 pm

Hi,

I'm not sure to understand what you want to do. I give a try so :
You would like to have a FAQ content. For this FAQ you would like to have a category filter ?

If it's that, you can easily reach some information :
- in each content template, the $node value is provided. you can use the following code to show what is inside this variable :

{$node|attribute(show,1)}

- in the $node, you've got the data_map array which is an array of your attributes. You can access the category attribute like this :

{$node.data_map.category}

- on each attribute, you can use the content function to get back the value of the content. For the selection datatype, the content function returns an int of the selected category. The list of category are stocked in the content of the content class attribute.

- finally, if you want to display all the faq filtered by a category, in your template a code like this :

<form action="{$node.url_alias|ezurl('no')}" action="post">
<select name="category">
{foreach $options as $o}
<option value="{$o.value}">{$o.name|wash}</option>
{/foreach}
</select>
</form>

- and to find your selected category :

{def $selected_category=ezhttp('category', 'post')}
{$selected_category}

Hope it helps...

Max

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

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 15:15:40
Script start
Timing: Jan 18 2025 15:15:40
Module start 'layout'
Timing: Jan 18 2025 15:15:40
Module start 'content'
Timing: Jan 18 2025 15:15:41
Module end 'content'
Timing: Jan 18 2025 15:15:41
Script end

Main resources:

Total runtime0.8346 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 589.0313152.6250
Module start 'layout' 0.00540.0040 741.656339.4453
Module start 'content' 0.00940.8241 781.1016540.0313
Module end 'content' 0.83350.0011 1,321.132812.1641
Script end 0.8346  1,333.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4079160.0002
Check MTime0.00140.1663160.0001
Mysql Total
Database connection0.00070.082710.0007
Mysqli_queries0.780593.5173540.0145
Looping result0.00050.0546520.0000
Template Total0.791594.820.3958
Template load0.00230.270120.0011
Template processing0.789294.567120.3946
Template load and register function0.00010.016810.0001
states
state_id_array0.00320.386110.0032
state_identifier_array0.00170.200320.0008
Override
Cache load0.00190.2327320.0001
Sytem overhead
Fetch class attribute can translate value0.00050.064320.0003
Fetch class attribute name0.00110.127830.0004
XML
Image XML parsing0.00060.077920.0003
class_abstraction
Instantiating content class attribute0.00000.001130.0000
General
dbfile0.00070.0845160.0000
String conversion0.00000.001140.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs