Could anyone please help me to create a template definition by java code, i
have use code to create template and page, but not find any way to create a
template definition.
[code]HierarchyManager hm= MgnlContext.getHierarchyManager("templates");
// strip off the .ftl extension
String nodeName = "installTemplateDemo";
Content template;
int idx = nodeName.lastIndexOf('/');
Content parent;
if (idx > 0) {
String parPath = nodeName.substring(0, idx);
if (hm.isExist(parPath)) {
parent = hm.getContent(parPath);
} else {
parent = ContentUtil.createPath(hm,
parPath, ItemType.FOLDER, true);
}
} else {
parent = hm.getRoot();
}
template = parent.createContent(nodeName.substring(idx
+ 1), ItemType.CONTENT);
template.createNodeData("enabled", Boolean.FALSE);
template.createNodeData("autoImport", Boolean.TRUE);
template.createNodeData("text");
if (!template.hasNodeData("text")) {
template.createNodeData("text");
}
template.getNodeData("text").setValue("template
demo...");
hm.save();[/code]
[code]Session session = MgnlContext.getJCRSession("website");
Node node = session.getNode("/demo-project");
Node pageNode = node.addNode("installPageDemo",
"mgnl:page");
pageNode.setProperty("title","Hello Page");
pageNode.setProperty("mgnl:template","templates:installTemplateDemo");
session.save();[/code]
Thanks!
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=25ce7940-d897-46a8-840f-517c5eabf842
----------------------------------------------------------------
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: <[email protected]>
----------------------------------------------------------------