How to do multiple section in a template with one array with multiple arrays inside?

Author Message

Mauricio Monsalve

Saturday 31 July 2004 7:03:39 am

Hi.

I'm developing a new class that will give me some advices when users search for any thing. When I got the SearchText variable, I let EZ do it's work and I seek in a semantic database the posible contexts for SearchText. What I got finally is a multiple array, it has a gloss(definition of the word), an a set of synonym (Synset) of word related to this meaning, and I got as many glosses and synsets as the database has.

So, it can be something like this:

myArray = [ [gloss, synsets[] ],
[gloss, synsets[] ] ]

So I'm setting myArray as a template variable.

The idea is to do a section and a loop to print this results, let's put it in a code like way.

for (each element of myArray)
{
print element.gloss
for (each element.synset)
{
print element.synset.word
}
}

And the result should look like this:
Gloss1: word1, word2, ....
Gloss2: word1, word2, word3....
...

I search in the documentation, and it shows me how to do a section and a loop for a single array, and I'm trying to write some things but it didn't work.

Anyone can help me about this?

Bård Farstad

Tuesday 10 August 2004 2:46:33 am

You can use section to do this. Here is a small example.

{let double_array=array( hash( 'name', 'First Glossary', 'values', array( 'Word1', 'Word2', 'Word3' ) ),
                         hash( 'name', 'Second Glossary', 'values', array( 'Word1', 'Word2', 'Word3' ) ) )}
{section var=single_array loop=$double_array}
    {$single_array.name}:
    {section var=value loop=$single_array.values}
        {$value}
        {delimiter},{/delimiter}
    {/section}
    {delimiter}<br/>{/delimiter}
{/section}
{/let}

--bård

Documentation: http://ez.no/doc

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