Forums / Setup & design / Code to automatically list content object attribute names and data

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.

eZ debug

Timing: Jan 18 2025 22:12:42
Script start
Timing: Jan 18 2025 22:12:42
Module start 'content'
Timing: Jan 18 2025 22:12:43
Module end 'content'
Timing: Jan 18 2025 22:12:43
Script end

Main resources:

Total runtime0.8724 sec
Peak memory usage4,096.0000 KB
Database Queries195

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.9844180.7969
Module start 'content' 0.00560.7544 768.7813512.7500
Module end 'content' 0.76000.1123 1,281.5313340.7422
Script end 0.8723  1,622.2734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.4437210.0002
Check MTime0.00140.1564210.0001
Mysql Total
Database connection0.00070.077310.0007
Mysqli_queries0.784989.96921950.0040
Looping result0.00200.22721930.0000
Template Total0.848297.220.4241
Template load0.00200.230820.0010
Template processing0.846296.997620.4231
Template load and register function0.00030.029410.0003
states
state_id_array0.00070.084510.0007
state_identifier_array0.00130.144020.0006
Override
Cache load0.00180.2108820.0000
Sytem overhead
Fetch class attribute can translate value0.00150.177020.0008
Fetch class attribute name0.00100.116650.0002
XML
Image XML parsing0.00630.717920.0031
class_abstraction
Instantiating content class attribute0.00000.002180.0000
General
dbfile0.01331.5299270.0005
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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