[DOCU-650] cmsfn examples Created: 04/Dec/15 Updated: 04/Jan/16 Resolved: 14/Dec/15 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Magnolia Malfunction | Priority: | Major |
| Reporter: | Luis Moreno | Assignee: | Antti Hietala |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Date of First Response: |
| Description |
|
Hello, These examples don't seemed to execute at all: cmsfn.asNodeList(contentMapList) [#assign myMapList = cmsfn.children(content, "mgnl:page")] cmsfn.children(content, nodeTypeName) <ul> This one generates the error below: cmsfn.asContentMapList(nodeList) [#assign childrenNodesAsContentMaps = cmsfn.asContentMapList(cmsfn.children(currentNode, "mgnl:page"))] Error (abridged): No compatible overloaded variation was found; declared parameter types and argument value types mismatch. (info.magnolia.jcr.util.ContentMap), (info.magnolia.jcr.util.ContentMap, String) Caused by: freemarker.core._TemplateModelException: No compatible overloaded variation was found; declared parameter types and argument value types mismatch.
Thanks. |
| Comments |
| Comment by Antti Hietala [ 11/Dec/15 ] |
|
Hi Luis, The cmsfn examples work but require a little bit setup. Let's look at them one by one. 1. Convert content map collection to node listPut the example code into a page template script. You can use for example the hello.ftl script which you can download with the Hello Magnolia tutorial.
[#assign myMapList = cmsfn.children(content, "mgnl:page")]
[#list cmsfn.asNodeList(myMapList) as child]
${cmsfn.parent(child)!},
[/#list]
Create a page structure where your page has a parent page and some child pages:
home <--- Parent page
└── animals <--- Execute the code in this page template
├── cats <--- Child pages
├── dogs
└── monkeys
What happens in the code:
Expected result:
2. ChildrenProbably the same issue with this example. The page where you run the script must have subpages and the subpages need to have titles. Otherwise the example doesn't render anything.
<ul>
[#list cmsfn.children(content, "mgnl:page") as child ]
<li>${child.title!}</li>
[/#list]
</ul>
Expected result:
3. Convert node collection to content map listYour example seems to be missing the first line where we assign currentNode. Try adding that line and run again.
[#assign currentNode = cmsfn.asJCRNode(content)]
[#assign childrenNodesAsContentMaps = cmsfn.asContentMapList(cmsfn.children(currentNode, "mgnl:page"))]
[#list childrenNodesAsContentMaps as child ]
${child.title!},
[/#list]
Expected result:
|
| Comment by Luis Moreno [ 22/Dec/15 ] |
|
Thanks Antti, Number 1 might be worth mentioning in the docs that it only works in that location as it isn't intuitive to deduced that functionality. Number 2 and 3 only work for me with Hello Magnolia. But my page structure is a bit more complex. home
└── animals
| ├── cats
| ├── dogs
| └── monkey
|
└── fish
| ├── catfish
| ├── dolphin
| └── sharks
|
└── birds
├── bluejays
├── doves
└── cardinals
Thanks! |
| Comment by Antti Hietala [ 04/Jan/16 ] |
|
Added some help for Running the examples |