[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")]
list cmsfn.asNodeList(myMapList) as child
${cmsfn.parent(child)!},
/#list

cmsfn.children(content, nodeTypeName)

<ul>
[#list cmsfn.children(content, "mgnl:page") as child ]
<li>${child.title!}</li>
/#list
</ul>

This one generates the error below:

cmsfn.asContentMapList(nodeList)

[#assign childrenNodesAsContentMaps = cmsfn.asContentMapList(cmsfn.children(currentNode,

"mgnl:page"))]
list childrenNodesAsContentMaps as child
${child.title!},
/#list

Error (abridged):

No compatible overloaded variation was found; declared parameter types and argument value types

mismatch.
The FTL type of the argument values were: Null, string (wrapper: f.t.SimpleScalar).
The Java type of the argument values were: Null, String.
The matching overload was searched among these members:
info.magnolia.templating.functions.TemplatingFunctions.children(javax.jcr.Node, String),
info.magnolia.templating.functions.TemplatingFunctions.children

(info.magnolia.jcr.util.ContentMap),
info.magnolia.templating.functions.TemplatingFunctions.children(javax.jcr.Node),
info.magnolia.templating.functions.TemplatingFunctions.children

(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.
The FTL type of the argument values were: Null, string (wrapper: f.t.SimpleScalar).
The Java type of the argument values were: Null, String.

  • Failed at: #assign childrenNodesAsContentMaps = ...

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 list

Put 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:

  1. Build a content map collection of the current page's (animals) children (cats, dogs, monkeys)
  2. Convert the map to a node list.
  3. Find each node's parent, which is the same for all nodes: animals

Expected result:

node /home/animals, node /home/animals, node /home/animals,

2. Children

Probably 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:

  • Cats
  • Dogs
  • Monkeys

3. Convert node collection to content map list

Your 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:

Cats, Dogs, Monkeys,

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

Generated at Mon Feb 12 01:11:08 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.