Code to automatically list content object attribute names and data

Author Message

Fraser Hore

Thursday 01 April 2004 8:52:28 am

I would like to set up a template that will fetch the child nodes and then display a table showing the content of the data map. The trick is, I would like this template to work for all classes, even custom ones. This way a user can create a class for themselves (e.g. Contacts), create a folder for objects of that class (e.g. Contact List), populate the folder with Contacts content objects, and then surf to their folder to see a list of their contacts.

I know this can be set up manually by fetching the child nodes and then creating a table with stuff like
<td>
$ContactLoop:item.data_map.first_name.content
</td>
<td>
$ContactLoop:item.data_map.first_name.content
</td>

But is there a way to design the template so you get the same result without knowing in advance what the content attributes will be?

I've figured out that i can fetch the class attributes using the class id to create the column headings. But I'm stumped on printing the data.

Ultimately I'd like to set up a "view" class to gather view parameters like which fields (or attributes) to show, how to sort, filter etc. Then the user could define their own views by adding "view" content objects in the same node as the content that they want to see, and the template could have a menu of these views. Clicking on the view link brings up a template that shows all "Contacts" in the same node.

Any suggestions would be greatly appreciated.

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.

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 19 2025 00:55:27
Script start
Timing: Jan 19 2025 00:55:27
Module start 'layout'
Timing: Jan 19 2025 00:55:27
Module start 'content'
Timing: Jan 19 2025 00:55:27
Module end 'content'
Timing: Jan 19 2025 00:55:27
Script end

Main resources:

Total runtime0.6933 sec
Peak memory usage4,096.0000 KB
Database Queries58

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 589.6016152.6563
Module start 'layout' 0.00580.0029 742.257839.4922
Module start 'content' 0.00880.6834 781.7500507.6406
Module end 'content' 0.69220.0011 1,289.390616.0938
Script end 0.6933  1,305.4844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4644160.0002
Check MTime0.00140.1982160.0001
Mysql Total
Database connection0.00080.110510.0008
Mysqli_queries0.619889.3963580.0107
Looping result0.00060.0907560.0000
Template Total0.660595.320.3302
Template load0.00190.269820.0009
Template processing0.658694.989020.3293
Template load and register function0.00020.028710.0002
states
state_id_array0.00110.156810.0011
state_identifier_array0.00070.106720.0004
Override
Cache load0.00180.2554820.0000
Sytem overhead
Fetch class attribute can translate value0.00060.090610.0006
Fetch class attribute name0.00100.143250.0002
XML
Image XML parsing0.00260.372110.0026
class_abstraction
Instantiating content class attribute0.00000.003680.0000
General
dbfile0.00380.5519160.0002
String conversion0.00000.001440.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs