Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added a demo file for ESP

...

For more options of the sling taglib see the tag lib definition file.

ESP

Here's a few of the objects and methods available in an ESP file:

Code Block
titlehtml.esp
borderStylesolid

<html>
<head><title>Sling ESP reference documentation</title>
</head>
<body>
	
<h2>Sling ESP documentation (work in progress)</h2>
<p>Have a look at this file's source or at Sling's ScriptableNodeTest.java</p><br/>
	
<%= 'tags: use \<%=  %\> to evaluate, \<%  %\> otherwise.' %>
<%  'e.g. this will not be printed'; %><br/>
<%

// create a new node under currentNode
var n = currentNode.addNode('n');
prt('path of n: ' + n.getPath());

// create new node and specify node type
var n2 = n.addNode('n2', 'nt:folder');

// set and get property
n.setProperty('thename', 'thevalue');
prt('get prop thename: ' + n['thename']               ); // thevalue
prt('another way: '      + n.thename                  ); // thevalue
prt('get type of n2:  '  + n2['jcr:primaryType']      ); // nt:folder
prt('test type of n2: '  + n2.isNodeType('nt:folder') ); // true

// iterate over properties
var props = n.getProperties();
for(i in props) { 
  prt('getProperties(): ' + props[i].name + ': ' + props[i].value.string); 
}

// getNodes()
n.addNode('abcd');
n.addNode('abcdef')
n.addNode('abcdefgh');
prt('get all nodes: ' +n.getNodes().length         ); // 4, incl n2	
prt('get abcd: '      +n.getNodes('abcd').length   ); // 1, abcd
prt('get abcde*: '    +n.getNodes('abcde*').length ); // 2, abcdef and abdefgh

// remove()
n.getNode('abcd').remove();
prt('removed abcd node ' + n.hasNode('abcd'));				// false

// get the root node (3 ways)
prt( currentNode.getAncestor(0));
prt( currentNode.session.getRootNode());
prt( currentNode.getSession().getRootNode());

// include the rendered result of another node (see Sling in 15 minutes)
// sling.include("/content/header", "forceResourceType=wiki.page,replaceSelectors=edit,replaceSuffix=validation");

function prt(s) { out.print(s+'<br/><br/>'); }
%>
</body>
</html>