Forum OpenACS Development: show variable assigned value

Collapse
Posted by Iuri Sampaio on
Hi there,

I created a loop to append categories to a list of elements used forward in a templatelist.
Although the element name comes correctly, the label of the second element is not properly assigned. 

The category_name of the second element, (which is the label of the element), gets repeated with the first element label appended.

Here it is the part of code that does the appending into the list of elements.

ns_log Notice "[videos::get_categories -package_id $package_id]"

foreach {category_id category_name } [videos::get_categories -package_id $package_id] {
    lappend list_elements cat_${category_id}  {
        label "$category_name"
        display_template { @videos.cat1@ }
    }
}

ns_log Notice "ELEMENTS: $list_elements"



and the error.log shows


[22/Jun/2010:18:50:56][13161.3045104528][-default:52-] Notice: 3188 | 3203 Licensa 3195 Tipo
[22/Jun/2010:18:50:56][13161.3045104528][-default:52-] Notice: ELEMENTS: image {
    label " "
        display_template {
        <a href="@videos.url@videos-view?video_id=@videos.video_id@">
        <img src="@videos.url@@videos.video_id@.jpg"></a>
        }
    } name {
    label "<span>#</span>videos.Name#"
    display_template {
        <a href="@videos.url@videos-view?video_id=@videos.video_id@">
        @videos.video_name@</a>
    }
    } autor {
    label "<span>#</span>videos.Author#"
    display_template {
        @videos.autor@
    }
    } description {
    label "<span>#</span>videos.Description#"
    display_template {
        @videos.video_description@
    }
    } cat_3203 {
    label "{$category_name}"
    display_template { @videos.cat1@}
    } cat_3195 {
    label "${category_name}"
    display_template { @videos.cat1@}
    }


So, as i said the name of the elements are correct
cat_3203  and cat_3195 but the labels don't.

In the Browser , instead of show "Tipo" and "Licensa" as two columns of the templatelist as we have at logs
[22/Jun/2010:18:50:56][13161.3045104528][-default:52-] Notice: 3188 | 3203 Licensa 3195 Tipo

it shows two columns but both with "Tipo" as their labels.
it seems the category_id follow the loop sequence but the category_name does not follow it.

how do a fix the variable $category_name
Collapse
Posted by Iuri Sampaio on
I finally got it working well 

Although i still don't see where the error was before,  lappend had errors somehow 

foreach {category_id category_name } [videos::get_categories -package_id $package_id] {
    ns_log Notice "ITEM: $category_id - $category_name"

    lappend list_elements cat_${category_id} [list \
          label [category::get_name $category_id] \
          display_col cat_$category_id]

 
then error.log  shows

[24/Jun/2010:12:05:28][16111.3034577808][-default:20-] Notice: ELEMENTS: image {
    label " "
        display_template {
        <a href="@videos.url@videos-view?video_id=@videos.video_id@">
        <img src="@videos.url@@videos.video_id@.jpg"></a>
        }
    } name {
    label "<span>#</span>videos.Name#"
    display_template {
        <a href="@videos.url@videos-view?video_id=@videos.video_id@">
        @videos.video_name@</a>
    }
    } autor {
    label "<span>#</span>videos.Author#"
    display_template {
        @videos.autor@
    }
    } description {
    label "<span>#</span>videos.Description#"
    display_template {
        @videos.video_description@
    }
    } cat_3203 {label Licensa display_col cat_3203} cat_3195 {label Tipo display_col cat_3195}