Share » Forums » Setup & design » Code to automatically list content...

Code to automatically list content object attribute names and data

Code to automatically list content object attribute names and data

Thursday 01 April 2004 8:52:28 am - 3 replies

Author Message

Fraser Hore

Tuesday 06 April 2004 1:48:13 pm

I figured out how to have the template automatically create a table that lists the class attribute names across the first row and then lists the content of those attributes for all children in subsequent rows. The child name in the first column links to the view of the child.

Next step is to create a class where the user can set parameters to control the way the list is displayed (e.g. attributes to include, filters etc.). It would also be great if the column headings could be clicked to sort by that attribute. If anyone wants to take a stab at these enhancements it would be a great help. The end result will be pretty powerful.

Here's the code:

{let attribute_content=fetch( content, list, hash( parent_node_id, $node.node_id))}
{section var=class loop=$attribute_content max=1}
{let attribute_name=fetch( 'content', 'class_attribute_list', hash( 'class_id', $class.item.object.contentclass_id ) )}

<table border="1">

<tr>
{section var=heading loop=$attribute_name}
<td>
{$heading.item.name|wash}
</td>
{/section}
</tr>

<tr>
{section var=record loop=$attribute_content}
{section var=attribute_name_link loop=$attribute_name max=1}
{let data=$attribute_name_link.item.identifier|wash}
<td>
<a href={concat("/content/view/full/",$record.item.node_id)|ezurl}>
{attribute_view_gui attribute=$record.item.object.data_map.$data}
</a>
</td>
{/let}
{/section}

{section var=attribute_variable loop=$attribute_name offset=1}
{let data=$attribute_variable.item.identifier|wash}
<td>
{attribute_view_gui attribute=$record.item.object.data_map.$data}
</td>
{/let}
{/section}
</tr>
{/section}

</table>

{/let}
{/section}
{/let}

For some reason {attribute_view_gui attribute=$record.item.object.data_map.$attribute_variable.item.identifier|wash} didn't work so I had to assign the $data variable. Also, at the moment it will only work for the first class type it comes across so it assumes that the folder only has one type of child class.

Cheers,

Fraser

Fraser Hore

Monday 12 April 2004 4:56:45 am

I would be grateful for some help with the attribute filter parameter. I've used the code:

{let attribute_content=fetch( content, list, hash( parent_node_id, $parent_node.node_id, 'attribute_filter', array('or', array('folder/description', '=', 'test'))))}

I have a child folder with 'test' in the description attribute. I am getting the full list of children and not just the child folder where description = test.

Any suggestions?

Thanks in advance

Fraser Hore

Monday 12 April 2004 5:17:33 am

I am using a section to loop through attribute names. I created a variable for the array of values to loop through called attribute_name. I can manually set my identifiers in the array like this:

{let attribute_name=array(Name, Description, Image)}

Then loop through and print the names like this:

{section var=heading loop=$attribute_name}
{$heading.item}</br>
{/section}

So far so good. But I want values in a text_line attribute called 'attribute_name_array' as the array. In this attribute I have entered; Name, Description.

Now I define the attribute_name variable as:

{let attribute_name=array($node.data_map.attribute_name_array.content)}

The output from this is 'Name, Description' all together rather than seperated (i.e. it's not looping through 'Name' then 'Description'.

I then added implode(', ') to try to separate them;

{let attribute_name=array($node.data_map.attribute_name_array.content)|implode(', ')}

and it separates each character rather than seperating at the ', ' delimiter.

Any suggestions would be greatly appreciated.

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu