Forums / Setup & design / Access selection datatype

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