Sling Cheatsheet

Published on November 2016 | Categories: Documents | Downloads: 330 | Comments: 0 | Views: 947
of 2
Download PDF   Embed   Report

Cheatsheet for the Apache Sling framework.

Comments

Content

understanding

Apache Sling
Sele cto r
Ex te ns ion

script resolution
Su ffix

1 2 3 4 5
Best match:

Metho d

HTTP Request

GET /wiki/Sling.edit.html/richtext?simple=true HTTP/1.1
Pat h Que ry Parame ters
Property title body Value Sling Intro <div>Hello World</div>

Content Resolution

/wiki/Sling
Node has properties

sling:resourceType

wiki/page

Get Resource Type

us e: sling:resourceType= fa llb ac k: sling:resourceSuperType=
wiki/page «null»

Resource Type

las t jcr:primaryType= re so rt: nt:file

Script Locations

eit he r:

/apps/wiki/page/

or: /libs/wiki/page/

Script Names
Extens ion
edit.esp html.esp
Worst match:

6
Script

edit.html.esp
Selecto r+Exten sion

GET.esp

Sele cto r

Met ho d

7

Include Options
sling.include("path", "forceResourceType= wiki/body, (Powerf ul) replaceSuffix= xhtml, addSelectors= foo.bar");

script"); <% log.info("Executing my rameter("simple")) { if (request.getRequestPa ttp://localhost/"); response.sendRedirect("h } %> <html> d> ode.title %></title></hea <head><title><%=currentN <body> ) %></h1> <h1><%=resource.getPath( String()); %> <% out.println(reader.to e.getPath() + "content", <% sling.include(resourc ; %> "replaceSelectors= edit") </body> </html>

<form action="/mynode" method="POST"> <input type="text" name="title"> <textarea name="body"> </form>

ing the SlingPostServlet Us r your
fo this is the default handler early POST requests. It can do n anything.
<form action="/mynode/" method="POST"> <input type="hidden" name=":name" value="new_node"> <input type="hidden" name=":nameHint" value="new node"> </form>

Create or update /mynode, set title and body. Set lastModified and lastModifiedBy automatically
<form action="/mynode/" method="POST"> <input type="text" name="dummy"> <input type="hidden" name=":order" value="first"> </form>

<input type="text" name="date1" value="2008-06-13T18:55:00"> <input type="text" name="date2"> <input type="hidden" name="date2@TypeHint" value="Date"> <input type="hidden" value="nt:file" name="./uploaded/jcr:primaryType">

Guess property type from date pattern, set property type explicitly and set node type explicitly
<form action="/old/node" method="POST"> <input type="hidden" name=":operation" value="copy"> <input type="hidden" name=":dest" value="/new/place"> <input type="hidden" name=":replace" value="true"> </form>

Create new node below /mynode and make it the first child (also valid: last, before x, after x, 3, 7, 9. <form action="/node" method="POST"> <input name=":operation" type="hidden" value="delete"> </form> Delete /node
<form action="/node" method="POST"> <input type="hidden" name=":operation" value="delete"> <input type="hidden" name=":applyTo" value="/node/one"> <input type="hidden" name=":applyTo" value="/node/two"> </form>

Create new node below /mynode, use name or name hint. Set created and createdBy automatically
<input type="text" name="customer"> <input type="hidden" value="John Doe" name="customer@DefaultValue" > <input type="hidden" name="title@Delete">

Copy /old/node to /new/place and replace the existing node there.
<input type="text" name="oldtitle"> <input type="hidden" value="oldtitle" name="newtitle@ValueFrom">

Take default value for customer property, remove the title property
<form action="/old/node" method="POST"> <input type="hidden" name=":operation" value="move"> <input type="hidden" name=":dest" value="/new/place"> </form>

Get value for property title from field oldtitle
<input type="hidden" value="/node/prop" name="title@CopyFrom">

Delete /node/one and /node/t wo

Move /old/node to /new/place

Copy property title from other node's property

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close