[MAGNOLIA-7077] Add tool to get the data structure of an object in templates Created: 16/May/17 Updated: 08/Aug/17 Resolved: 14/Jul/17 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.5.6 |
| Type: | New Feature | Priority: | Neutral |
| Reporter: | Christopher Zimmermann | Assignee: | Jaroslav Simak |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Template: |
|
||||||||
| Acceptance criteria: |
Empty
|
||||||||
| Documentation update required: |
Yes
|
||||||||
| Date of First Response: | |||||||||
| Epic Link: | LD: Fundamental features | ||||||||
| Sprint: | Kromeriz 101, Kromeriz 103, Kromeriz 104, Kromeriz 105 | ||||||||
| Story Points: | 8 | ||||||||
| Description |
|
Some way for a templater to output the structure and content of an object within a template for development purposes. Why: Example usage:
${cmsfn.dump(myObject)} # outputs object properties as text with default depth of 3
or
${cmsfn.dump(myObject, 5)} # outputs object properties as text with depth of 5
or
${cmsfn.dump(myObject, 5, true)} # outputs object properties as html with depth of 5
Describers for following types are provided out of the box:
Node: Node (/magnolia-travels/Vietnam--Tradition-and-Today)
author = "Magnolia Travels" (String)
body = "<p>Vietnam is one of the world’s most exotic and culturally rich destinations. A gem..." (String)
body_de = "<p>Vietnam ist eine der exotischsten und kulturreichsten Destinationen weltweit. Als Juwel unt..." (String)
description = "Discover the culture and everyday treasures of a rising phoenix" (String)
description_de = "Entdecken Sie die Kultur und die alltäglichen Schätze eines Phoenix aus der Asche" (String)
destination = Sequence (1)
0 = "7ec72c48-c33f-418e-b2ff-44cfb4bbb1f2" (String)
duration = "14" (String)
image = "jcr:1044b3b8-30b1-48fe-8078-832b6cef8fb5" (String)
isFeatured = true (Boolean)
location = "Ho Chi Minh City, Vietnam" (String)
name = "Vietnam: Tradition and Today" (String)
name_de = "Vielfältiges Vietnam" (String)
tourTypes = Sequence (2)
0 = "415025c6-e4b5-4506-9384-34f428a52104" (String)
1 = "e007e401-1bf8-4658-8293-b9c743784264" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:57:18 AM (Date)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:48:49 AM (Date)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 12:20:06 PM (Date)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (Date)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "3d676477-eabc-4cbe-88b6-b77aa85a358a" (String)
Property: Magnolia Travels (Property) Multivalue Property: Property (2) 0 = "415025c6-e4b5-4506-9384-34f428a52104" (String) 1 = "e007e401-1bf8-4658-8293-b9c743784264" (String) ContentMap: ContentMap (/magnolia-travels/Vietnam--Tradition-and-Today)
author = "Magnolia Travels" (String)
body = "<p>Vietnam is one of the world’s most exotic and culturally rich destinations. A gem..." (String)
body_de = "<p>Vietnam ist eine der exotischsten und kulturreichsten Destinationen weltweit. Als Juwel unt..." (String)
depth = null (Null)
description = "Discover the culture and everyday treasures of a rising phoenix" (String)
description_de = "Entdecken Sie die Kultur und die alltäglichen Schätze eines Phoenix aus der Asche" (String)
destination = Sequence (1)
0 = "7ec72c48-c33f-418e-b2ff-44cfb4bbb1f2" (String)
duration = "14" (String)
id = null (Null)
image = "jcr:1044b3b8-30b1-48fe-8078-832b6cef8fb5" (String)
isFeatured = true (Boolean)
location = "Ho Chi Minh City, Vietnam" (String)
name = "Vietnam: Tradition and Today" (String)
name_de = "Vielfältiges Vietnam" (String)
nodeType = null (Null)
path = null (Null)
tourTypes = Sequence (2)
0 = "415025c6-e4b5-4506-9384-34f428a52104" (String)
1 = "e007e401-1bf8-4658-8293-b9c743784264" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:57:18 AM (GregorianCalendar)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:48:49 AM (GregorianCalendar)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 12:20:06 PM (GregorianCalendar)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (GregorianCalendar)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "3d676477-eabc-4cbe-88b6-b77aa85a358a" (String)
Sequence of ContentMaps: Sequence (36)
0 = ContentMap (/magnolia-travels/Vietnam--Tradition-and-Today)
author = "Magnolia Travels" (String)
body = "<p>Vietnam is one of the world’s most exotic and culturally rich destinations. A gem..." (String)
body_de = "<p>Vietnam ist eine der exotischsten und kulturreichsten Destinationen weltweit. Als Juwel unt..." (String)
depth = null (Null)
description = "Discover the culture and everyday treasures of a rising phoenix" (String)
description_de = "Entdecken Sie die Kultur und die alltäglichen Schätze eines Phoenix aus der Asche" (String)
destination = Sequence (1)
0 = "7ec72c48-c33f-418e-b2ff-44cfb4bbb1f2" (String)
duration = "14" (String)
id = null (Null)
image = "jcr:1044b3b8-30b1-48fe-8078-832b6cef8fb5" (String)
isFeatured = true (Boolean)
location = "Ho Chi Minh City, Vietnam" (String)
name = "Vietnam: Tradition and Today" (String)
name_de = "Vielfältiges Vietnam" (String)
nodeType = null (Null)
path = null (Null)
tourTypes = Sequence (2)
0 = "415025c6-e4b5-4506-9384-34f428a52104" (String)
1 = "e007e401-1bf8-4658-8293-b9c743784264" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:57:18 AM (GregorianCalendar)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:48:49 AM (GregorianCalendar)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 12:20:06 PM (GregorianCalendar)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (GregorianCalendar)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "3d676477-eabc-4cbe-88b6-b77aa85a358a" (String)
1 = ContentMap (/magnolia-travels/Hut-to-Hut-in-the-Swiss-Alps)
author = "Magnolia Travels" (String)
body = "<p>Some Swiss people are going to be pretty annoyed with us for revealing their secrets. Hush...." (String)
body_de = "<p>Einige Schweizer werden sich ärgern, dass wir ihre Geheimnisse aufdecken. Psst... ..." (String)
depth = null (Null)
description = "There's more to Switzerland than skiing" (String)
description_de = "Die Schweiz ist mehr als nur Skifahren" (String)
destination = Sequence (1)
0 = "6cc50e28-fb0e-4e49-b3b6-728690a2e861" (String)
duration = "7" (String)
id = null (Null)
image = "jcr:80d091ae-22ce-4cfc-b302-cb39f25c3d30" (String)
location = "Zurich, Switzerland" (String)
name = "Hut to Hut in the Swiss Alps" (String)
name_de = "Von Hütte zu Hütte in den Schweizer Alpen" (String)
nodeType = null (Null)
path = null (Null)
tourTypes = Sequence (1)
0 = "eaf9a648-fae1-48ae-a293-69bed874f159" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:55:07 AM (GregorianCalendar)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:48:52 AM (GregorianCalendar)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 11:36:14 AM (GregorianCalendar)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (GregorianCalendar)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "d30b9ca6-e22d-45c5-9456-7538ab7bccf8" (String)
2 = ContentMap (/magnolia-travels/West-Coast---Highway-101)
author = "Magnolia Travels" (String)
body = "<p>Imagine walking in the footsteps of the explorers, missionaries, and soldiers who made Amer..." (String)
body_de = "<p>Stellen Sie sich vor, dass Sie auf den Spuren der Forscher, Missionare und Soldaten unterwe..." (String)
depth = null (Null)
description = "Family travels in USA" (String)
description_de = "Familienreisen in den USA" (String)
destination = Sequence (1)
0 = "ed3dcd18-78af-46df-a9e1-bc732479f2e7" (String)
duration = "7" (String)
id = null (Null)
image = "jcr:d44f783c-91ca-4b48-9533-ea4e147e13e9" (String)
location = "Seattle, USA" (String)
name = "West Coast - Highway 101" (String)
name_de = "Westküste - Highway 101" (String)
nodeType = null (Null)
path = null (Null)
tourTypes = Sequence (1)
0 = "17da160b-da66-4e09-9e31-5fd040880f4a" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:51:38 AM (GregorianCalendar)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:48:56 AM (GregorianCalendar)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 11:40:45 AM (GregorianCalendar)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (GregorianCalendar)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "730c8850-d638-4e91-b3fb-4041a0c59ffe" (String)
3 = ContentMap (/magnolia-travels/Inside-New-Delhi)
author = "Magnolia Travels" (String)
body = "<p>Delhi has many interesting monuments and museums, but <em>we won't be visitin..." (String)
body_de = "<p>Delhi hat viele interessante Baudenkmäler und Museen, aber wir besuchen auf dieser..." (String)
depth = null (Null)
description = "Get to know Delhi up close and personal" (String)
description_de = "Lernen Sie Delhi ganz aus der Nähe und intim kennen" (String)
destination = Sequence (1)
0 = "7ec72c48-c33f-418e-b2ff-44cfb4bbb1f2" (String)
duration = "2" (String)
id = null (Null)
image = "jcr:ad33e9b0-855e-4bac-b35e-3c7e7588465c" (String)
location = "New Delhi, India" (String)
name = "Inside New Delhi" (String)
name_de = "In Neu Delhi eintauchen" (String)
nodeType = null (Null)
path = null (Null)
tourTypes = Sequence (2)
0 = "415025c6-e4b5-4506-9384-34f428a52104" (String)
1 = "e007e401-1bf8-4658-8293-b9c743784264" (String)
mgnl:activationStatus = true (Boolean)
mgnl:comment = "" (String)
mgnl:created = Jan 29, 2015 07:50:20 AM (GregorianCalendar)
mgnl:createdBy = "superuser" (String)
mgnl:lastActivated = Jul 1, 2015 08:49:03 AM (GregorianCalendar)
mgnl:lastActivatedBy = "superuser" (String)
mgnl:lastModified = Jun 18, 2015 11:41:28 AM (GregorianCalendar)
mgnl:lastModifiedBy = "superuser" (String)
jcr:created = Jun 12, 2017 01:41:27 PM (GregorianCalendar)
jcr:createdBy = "admin" (String)
jcr:primaryType = "mgnl:content" (String)
jcr:uuid = "3ba5ba55-ac02-4b37-a429-5fc0bb4b383b" (String)
...
Hash: Hash (2)
foo = "bar" (String)
baz = Hash (3)
i = "am" (String)
nested = "hash" (String)
yay! = Hash (1)
hi = "bye" (String)
|
| Comments |
| Comment by Christopher Zimmermann [ 16/May/17 ] |
|
I guess its easiest to have a method that runs in the JS context, but if it could be a method that runs directly in the Java context that would be easiest because a dev could directly print it from the FTL instead of needing to pass it out of the function in order to print it. |
| Comment by Bradley Andersen [ 16/May/17 ] |
|
smthn like php var_dump() or perl Data::Dumper would be great for FTLs in general. yeah we can call any public java method so we can introspect, but, the way the nodes are (wrapped(wrapped(wrapped))) makes it hard in that context to discover what the actual object is. this is asked about in every single training. |
| Comment by Christopher Zimmermann [ 16/May/17 ] |
|
bandersen Have a look at this macro, it might address what you are describing: https://git.magnolia-cms.com/users/czimmermann/repos/js-model-samples/browse/light-modules/js-model-samples/templates/macros/allProperties.ftl |
| Comment by Christopher Zimmermann [ 07/Jun/17 ] |
|
I agree that the current JSON format is hard to read. I think nesting is common - for example a tour has a sequence of categories. Also calling cmsfn.children returns a sequence of items. Please see proposal for output format here: |
| Comment by Christopher Zimmermann [ 15/Jun/17 ] |
|
Looking great. I would like to have this feature available by default as it will be useful for potentially any project. Therefore I suggest that the method is available in cmsfn. |
| Comment by Christopher Zimmermann [ 08/Aug/17 ] |
|
Please update the description with the actual method names and include a short description of how to use the inspector in an ftl template, and in a js model (if possible). |