Discussion:
using function from ftl script
Mario Martínez Campos (via Magnolia Forums)
2012-10-19 12:42:51 UTC
Permalink
Hi! I am quite new in magnolia. I have the following problem. I have a ftl script with this content:

[code]
[#if model.sections?has_content]
[#list model.sections as item]
<li><a href="${cmsfn.link(item)}">${item.title!'section'}</a></li>
[#assign children = model.subSection(item)]
.......MORE CODE HERE...
[/#list]
[/#if]
[/code]

and a model class with these functions:

[code]
public Collection<ContentMap> getSections() throws RepositoryException{

Collection<Node> sections = new ArrayList<Node> ();
Node root = this.getSiteRoot();
if(this.isShowInNav(root)){
sections.add(root);
}
NodeIterator it = root.getNodes();
while(it.hasNext()){
Node n = it.nextNode();
if(this.isShowInNav(n)){
sections.add(n);
}

}
return templatingFunction.asContentMapList(sections);
}


public Collection<ContentMap> getSubSections(ContentMap contentMap) {
return getSubSections(templatingFunction.asJCRNode(contentMap));

}

public Collection<ContentMap> getSubSections(Node node) {
Collection<Node> sections = new ArrayList<Node> ();
NodeIterator it;
try {
it = node.getNodes();
while(it.hasNext()){
Node n = it.nextNode();
if(this.isShowInNav(n)){
sections.add(n);
}

}
} catch (RepositoryException e) {
e.printStackTrace();
return new ArrayList<ContentMap>();
}

return templatingFunction.asContentMapList(sections);
}
[/code]

When I am using [b]model.sections[/b], everything is OK, but when I try to use [b]model.subSection(item)[/b] I get these annoying yellow page with the text

[code]Expression model.subSection is undefined on line 14, column 71 in tangent90/templates/global/header.ftl.
The problematic instruction:
----------
==> assignment: children=model.subSection(item) [on line 14, column 51 in tangent90/templates/global/header.ftl]
in include "/tangent90/templates/global/header.ftl" [on line 6, column 1 in tangent90/templates/home.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression model.subSection is undefined on line 14, column 71 in tangent90/templates/global/header.ftl.

.....[/code]


I have checked that is not problem with the java code because it never been executed and I tried with "model.getSubSection(item)", "model.subsection(item)",etc....

Any help??


Thanks!
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=d8b2fc0f-e371-43c0-8444-e0ddf6d3bf88


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Roland Polzer
2012-10-19 12:57:41 UTC
Permalink
getSubsections, not getSubsection (plural)



----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Roland Polzer
2012-10-19 13:00:31 UTC
Permalink
Post by Roland Polzer
getSubsections, not getSubsection (plural)
getSubSections (and with capital S, of course)


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Mario Martínez Campos (via Magnolia Forums)
2012-10-19 13:24:29 UTC
Permalink
Thanks a lot! just another question. If I have a function in the model called getFoo() how I know if I have to use ${model.foo} or ${model.getFoo}??
Thanks!
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=d8b2fc0f-e371-43c0-8444-e0ddf6d3bf88


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Roland Polzer
2012-10-19 13:27:52 UTC
Permalink
Both should work, but If you specify parameters foo(parm) will not work and you must use getFoo(parm)



----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Roland Polzer
2012-10-19 13:30:41 UTC
Permalink
It would be ${model.getFoo()}, and not ${model.getFoo}


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------

Loading...