incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling Website > Discover Sling in 15 minutes
Date Thu, 02 Jun 2011 16:53:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Discover+Sling+in+15+minutes">Discover
Sling in 15 minutes</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (23)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:title=html.esp} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;html&gt;
  &lt;body&gt;     &lt;h1&gt;&lt;%= currentNode.title %&gt;&lt;/h1&gt;
  &lt;/body&gt; &lt;/html&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;html&gt;
<br>  &lt;body&gt; <br>    &lt;h1&gt;&lt;%= currentNode.title
%&gt;&lt;/h1&gt; <br>  &lt;/body&gt; <br>&lt;/html&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* and appends _html.esp_, as the extension
of our URL is _html_ and the language of our script is _esp_. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Store this script under <span
class="diff-changed-words">_<span class="diff-added-chars"style="background-color: #dfd;">/</span>apps/foo/bar/html.esp_,</span>
either using a WebDAV client (connected to [http://admin:admin@localhost:8080/]), or using
cURL as shown here, after creating the _html.esp_ script in the current directory on your
system: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-X MKCOL http://admin:admin@localhost:8080/apps/foo <br>curl -X MKCOL http://admin:admin@localhost:8080/apps/foo/bar
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-X MKCOL -u admin:admin http://localhost:8080/apps/foo <br>curl -X MKCOL -u admin:admin
http://localhost:8080/apps/foo/bar <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-T html.esp http://admin:admin@localhost:8080/apps/foo/bar/html.esp <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-u admin:admin -T html.esp http://localhost:8080/apps/foo/bar/html.esp <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. Let Sling generate the path of
a newly created node. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >To create a node with a unique
path at a given location, end the URL of the POST request with <span class="diff-changed-words">_/<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">\*</span>_.</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>In this case, the Sling
response redirects to the URL of the created node. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-X POST &quot;http://admin:admin@localhost:8080/content/blog&quot; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-X POST -u admin:admin &quot;http://localhost:8080/content/blog&quot; <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-changed-lines" >curl -D - <span class="diff-added-words"style="background-color:
#dfd;">-u admin:admin</span> -F&quot;title=Adventures with Sling&quot; <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&quot;http://admin:admin@localhost:8080/content/blog/*&quot;</span>
<span class="diff-added-words"style="background-color: #dfd;">&quot;http://localhost:8080/content/blog/&quot;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:title=header.esp}
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;div&gt;
  &lt;p style=&quot;color:blue;&quot;&gt;     &lt;img src=&quot;/images/sling.jpg&quot;
align=&quot;right&quot;/&gt;     &lt;%= currentNode.headline %&gt;   &lt;/p&gt;
&lt;/div&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;div&gt;
<br>  &lt;p style=&quot;color:blue;&quot;&gt; <br>    &lt;img
src=&quot;/images/sling.jpg&quot; align=&quot;right&quot;/&gt; <br>
   &lt;%= currentNode.headline %&gt; <br>  &lt;/p&gt; <br>&lt;/div&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-X MKCOL  http://admin:admin@localhost:8080/apps/foo/header/ <br>curl -T header.esp
http://admin:admin@localhost:8080/apps/foo/header/html.esp <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-X MKCOL -u admin:admin http://localhost:8080/apps/foo/header/ <br>curl -u admin:admin
-T header.esp http://localhost:8080/apps/foo/header/html.esp <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-changed-lines" >curl <span class="diff-added-words"style="background-color:
#dfd;">-u admin:admin</span> -F&quot;sling:resourceType=foo/header&quot;
-F&quot;headline=Hello, Sling world&quot; <span class="diff-changed-words">http://<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">admin:admin@</span>localhost:8080/content/header</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-X MKCOL  http://admin:admin@localhost:8080/images/ <br>curl -T sling.jpg  http://admin:admin@localhost:8080/images/sling.jpg
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-X MKCOL -u admin:admin http://localhost:8080/images/ <br>curl -u admin:admin -T sling.jpg
http://localhost:8080/images/sling.jpg <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:title=html.esp} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;html&gt;
  &lt;body&gt;     &lt;div id=&quot;header&quot;&gt;       &lt;%
sling.include(&quot;/content/header&quot;); %&gt;     &lt;/div&gt;   
 &lt;h1&gt;&lt;%= currentNode.title %&gt;&lt;/h1&gt;   &lt;/body&gt;
&lt;/html&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;html&gt;
<br>  &lt;body&gt; <br>    &lt;div id=&quot;header&quot;&gt;
<br>      &lt;% sling.include(&quot;/content/header&quot;); %&gt; <br>
   &lt;/div&gt; <br>    &lt;h1&gt;&lt;%= currentNode.title %&gt;&lt;/h1&gt;
<br>  &lt;/body&gt; <br>&lt;/html&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{noformat} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">curl
-T html.esp http://admin:admin@localhost:8080/apps/foo/bar/html.esp <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">curl
-u admin:admin -T html.esp http://localhost:8080/apps/foo/bar/html.esp <br></td></tr>
            <tr><td class="diff-unchanged" >{noformat} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="DiscoverSlingin15minutes-DiscoverSlingin15minutestheSlingLaunchpad"></a>Discover
Sling in 15 minutes - the Sling Launchpad</h1>

<p>The Sling Launchpad is a ready-to-run Sling configuration, providing an embedded
JCR content repository and web server, a selection of Sling components, documentation and
examples. The Launchpad makes it easy to get started with Sling and to develop script-based
applications.</p>

<p>This page will help you get started with the Launchpad. Fifteen minutes should be
enough to get an overview of what Sling does.</p>

<p>While simple to run and understand, the Launchpad is a full-featured instance of
Sling, an example configuration that we have created with the most common modules and configurations.
The full functionality of Sling is available by loading additional Sling (or custom) OSGi
bundles as needed, using the Launchpad's web-based OSGi management console.</p>

<h2><a name="DiscoverSlingin15minutes-SeeAlso"></a>See Also</h2>


<p>Example applications and mini-applications for Sling can be found under <a href="http://svn.apache.org/repos/asf/sling/trunk/samples/"
class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/sling/trunk/samples/</a>
(each application has a <tt>README.txt</tt> file, see these for more details).</p>

<p>Once you grok the basic examples of this page, we recommend studying the <em>espblog</em>
and <em>webloader</em> samples for more complete examples. The <em>javashell</em>
sample is useful to play with JCR java code (or any java code, for that matter) interactively.</p>

<h2><a name="DiscoverSlingin15minutes-Prerequisites"></a>Prerequisites</h2>

<p>We'll start with the self-runnable jar from the Sling distribution, you only need
a Java 5 JDK. Download the latest release from the Sling <a href="/confluence/display/SLINGxSITE/Downloads"
title="Downloads">Downloads</a> page or by clicking this link: <a href="http://www.apache.org/dyn/closer.cgi/sling/org.apache.sling.launchpad-6-standalone.jar"
class="external-link" rel="nofollow">org.apache.sling.launchpad-6-standalone.jar</a>.
Alternatively you can deploy the <a href="http://www.apache.org/dyn/closer.cgi/sling/org.apache.sling.launchpad-6.war"
class="external-link" rel="nofollow">Sling Web application</a> into any decent Servlet
Container such as Jetty or Tomcat or you can <a href="/confluence/display/SLINGxSITE/Getting+and+Building+Sling"
title="Getting and Building Sling">build the current source yourself</a>.</p>

<p>To show the simplicity of the REST-style approach taken by Sling the examples below
will be using <a href="http://curl.haxx.se/" class="external-link" rel="nofollow">cURL</a>.
Any HTTP client would do, but cURL is the easiest to document in a reproducible way.</p>

<p>A WebDAV client makes editing server-side scripts much more convenient, but to make
our examples easy to reproduce, we're using cURL below to create and update files in the JCR
repository, via the Sling WebDAV server.</p>


<h2><a name="DiscoverSlingin15minutes-StarttheLaunchpad"></a>Start the Launchpad</h2>

<p>After downloading the Sling Launchpad self-runnable jar just start it as follows:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>$ java -jar org.apache.sling.launchpad-6-standalone.jar
</pre>
</div></div>

<p>This starts the Sling embedded Web Server on port 8080 and writes application files
into the <tt>sling</tt> folder found in the current working directory.</p>

<p>Once started, look at <a href="http://localhost:8080/system/console/bundles" class="external-link"
rel="nofollow">http://localhost:8080/system/console/bundles</a> with your browser.
Use <em>admin</em> with password <em>admin</em> if Sling asks you
for a login. Sling then displays the <em>Felix Web Management Console</em> page.</p>


<p>On the bundles page, all bundles should be marked <em>Active</em>. They're
all <a href="http://www.osgi.org/" class="external-link" rel="nofollow">OSGi</a>
bundles powered by <a href="http://felix.apache.org" class="external-link" rel="nofollow">Apache
Felix</a>, but that doesn't really matter to us right now.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Log files</b><br
/>If things go wrong, have a look at the <tt>sling/logs/error.log</tt> log
file &#45; that's where Sling writes any error messages.</td></tr></table></div>

<h2><a name="DiscoverSlingin15minutes-Createsomecontent"></a>Create some
content</h2>

<p>Until we have ready-to-test forms, you can create content with cURL, or you can create
an HTML form that posts to the specified URL.</p>

<p>To create a content node (nodes are a <a href="http://jackrabbit.apache.org/"
class="external-link" rel="nofollow">JCR</a> concept, a unit of storage) with cURL,
use:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -u admin:admin -F"sling:resourceType=foo/bar" -F"title=some title" http://localhost:8080/content/mynode
</pre>
</div></div>

<p>The resulting node can be seen at <a href="http://localhost:8080/content/mynode.html"
class="external-link" rel="nofollow">http://localhost:8080/content/mynode.html</a>,
or as json format under <a href="http://localhost:8080/content/mynode.json" class="external-link"
rel="nofollow">http://localhost:8080/content/mynode.json</a>. Lets try with cURL:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>$ curl http://localhost:8080/content/mynode.json
{"title":"some title","sling:resourceType":"foo/bar","jcr:primaryType":"nt:unstructured"}
</pre>
</div></div>

<p>This returns the properties of the <tt>/content/mynode</tt> in JSON format
as we have created it above. The additional property <tt>jcr:primaryType</tt>
is a special JCR property indicating the JCR primary node type.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Monitoring requests</b><br
/>Sling provides a simple tool (an OSGi console plugin) to monitor HTTP requests, which
helps understand how things work internally. See the <a href="/confluence/display/SLINGxSITE/Monitoring+Requests"
title="Monitoring Requests">Monitoring Requests</a> page for details.</td></tr></table></div>

<h2><a name="DiscoverSlingin15minutes-Renderyourcontentusingserversidejavascript%28ESP%29"></a>Render
your content using server-side javascript (ESP)</h2>

<p>Sling uses scripts or servlets to render and process content.</p>

<p>Several scripting languages are available as additional Sling modules (packaged as
OSGi <em>bundles</em> that can be installed via the Sling management console),
but the launchpad currently includes the ESP (server-side ECMAscript), JSP (Java Server Pages),
and Groovy language modules by default.</p>

<p>To select a script, Sling uses the node's <em>sling:resourceType</em>
property, if it is set.</p>

<p>That is the case in our example, so the following script will be used by Sling to
render the node in HTML, if the script is found at <em>/apps/foo/bar/html.esp</em>
in the repository.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>html.esp</b></div><div class="codeContent
panelContent">
<pre class="code-java">
&lt;html&gt;
  &lt;body&gt;
    &lt;h1&gt;&lt;%= currentNode.title %&gt;&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div>

<p>To select the script, Sling:</p>
<ul>
	<li>looks under <em>/apps</em></li>
	<li>and appends the <em>sling:resourceType</em> value of our node ( which
is <em>foo/bar</em> )</li>
	<li>and appends <em>html.esp</em>, as the extension of our URL is <em>html</em>
and the language of our script is <em>esp</em>.</li>
</ul>


<p>Store this script under <em>/apps/foo/bar/html.esp</em>, either using
a WebDAV client (connected to <a href="http://admin:admin@localhost:8080/" class="external-link"
rel="nofollow">http://admin:admin@localhost:8080/</a>), or using cURL as shown here,
after creating the <em>html.esp</em> script in the current directory on your system:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -X MKCOL -u admin:admin http://localhost:8080/apps/foo
curl -X MKCOL -u admin:admin http://localhost:8080/apps/foo/bar
</pre>
</div></div>

<p>create a local file <em>html.esp</em> and copy above content.</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -u admin:admin -T html.esp http://localhost:8080/apps/foo/bar/html.esp
</pre>
</div></div>

<p>The HTML rendering of your node, at <a href="http://localhost:8080/content/mynode.html"
class="external-link" rel="nofollow">http://localhost:8080/content/mynode.html</a>,
is now created by this ESP script. You should see the node's title alone as an &lt;h1&gt;
element in that page.</p>

<p>A script named <em>POST.esp</em> instead of <em>html.esp</em>
would be called for a POST request, <em>DELETE.esp</em> for DELETE, <em>xml.esp</em>
for a GET request with a <em>.xml</em> extension, etc. See <a href="http://cwiki.apache.org/SLING/url-to-script-resolution.html"
class="external-link" rel="nofollow">URL to Script Resolution</a> on the Sling wiki
for more info.</p>

<p>Servlets can also be easily "wired" to handle specific resource types, extensions,
etc., in the simplest case by using SCR annotations in the servlet source code. Servlets and
scripts are interchangeable when it comes to processing Sling requests.</p>


<h2><a name="DiscoverSlingin15minutes-Whatnext%3F"></a>What next?</h2>

<p>These simple examples show how Sling uses scripts to work with JCR data, based on
<em>sling:resourceType</em> or node types.</p>

<p>There's much more to Sling of course - you'll find some additional simple examples
below, and above in the <em>see also</em> section.</p>

<p>We are working on debugging features to help trace the way Sling processes requests.
Have a look at <a href="https://issues.apache.org/jira/browse/SLING-3" class="external-link"
rel="nofollow">SLING-3</a> to see what's possible already.</p>


<h1><a name="DiscoverSlingin15minutes-Additionalexamples"></a>Additional
examples</h1>

<h2><a name="DiscoverSlingin15minutes-LetSlinggeneratethepathofanewlycreatednode."></a>Let
Sling generate the path of a newly created node.</h2>

<p>To create a node with a unique path at a given location, end the URL of the POST
request with <em>/</em>.</p>

<p>In this case, the Sling response redirects to the URL of the created node.</p>

<p>Start by creating a new <em>/blog</em> folder:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -X POST -u admin:admin "http://localhost:8080/content/blog"
</pre>
</div></div>

<p>And create a node with a Sling-generated name under it:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -D - -u admin:admin -F"title=Adventures with Sling" "http://localhost:8080/content/blog/"
</pre>
</div></div>

<p>Using cURL's <em>&#45;D</em> option shows the full HTTP response,
which includes a <em>Location</em> header to indicate where the new node was created:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>Location: http://localhost:8080/content/blog/adventures_with_slin_0
</pre>
</div></div>

<p>The actual node name might not be <em>adventures_with_slin_0</em> &#45;
depending on existing content in your repository, Sling will find a unique name for this new
node, based on several well-know property values like title, description, etc. which are used
for this if provided.</p>

<p>So, in our case, our new node can be displayed in HTML via the <a href="http://localhost:8080/content/blog/adventures_with_slin_0.html"
class="external-link" rel="nofollow">http://localhost:8080/content/blog/adventures_with_slin_0.html</a>
URL.</p>

<p>Note that we didn't set a <em>sling:resourceType</em> property on our
node, so if you want to render that node with a script, you'll have to store the script under
<em>/apps/nt/unstructured/html.esp</em>.</p>


<h2><a name="DiscoverSlingin15minutes-Addapageheaderwithsling.include"></a>Add
a page header with sling.include</h2>

<p>The <em>sling.include</em> function can be called from scripts to include
the rendered result of another node.</p>

<p>In this example, we create a node at <em>/content/header</em>, rendered
with a logo using an <em>html.esp</em> script, then use that header at the top
of the <em>html.esp</em> script that we created previously for the <em>foo/bar</em>
resource type.</p>

<p>Start by checking that <a href="http://localhost:8080/content/mynode.html" class="external-link"
rel="nofollow">http://localhost:8080/content/mynode.html</a> is rendered using the
<em>html.esp</em> script created above.</p>

<p>Create this script and name it <em>header.esp</em>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>header.esp</b></div><div class="codeContent
panelContent">
<pre class="code-java">
&lt;div&gt;
  &lt;p style=<span class="code-quote">"color:blue;"</span>&gt;
    &lt;img src=<span class="code-quote">"/images/sling.jpg"</span> align=<span
class="code-quote">"right"</span>/&gt;
    &lt;%= currentNode.headline %&gt;
  &lt;/p&gt;
&lt;/div&gt;
</pre>
</div></div>

<p>Upload it so that it is used to render resources having <em>sling:resourceType=foo/header</em>:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -X MKCOL -u admin:admin http://localhost:8080/apps/foo/header/
curl -u admin:admin -T header.esp http://localhost:8080/apps/foo/header/html.esp
</pre>
</div></div>

<p>Create the header node:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -u admin:admin -F"sling:resourceType=foo/header" -F"headline=Hello, Sling
world" http://localhost:8080/content/header
</pre>
</div></div>

<p>Upload the logo that the script uses (using sling.jpg or another logo in the current
directory):</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -X MKCOL -u admin:admin http://localhost:8080/images/
curl -u admin:admin -T sling.jpg http://localhost:8080/images/sling.jpg
</pre>
</div></div>

<p>And check that the header is rendered with the logo at <a href="http://localhost:8080/content/header.html"
class="external-link" rel="nofollow">http://localhost:8080/content/header.html</a>.</p>

<p>Now, update the html.esp script that we created for our first example above, to include
the header:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>html.esp</b></div><div class="codeContent
panelContent">
<pre class="code-java">
&lt;html&gt;
  &lt;body&gt;
    &lt;div id=<span class="code-quote">"header"</span>&gt;
      &lt;% sling.include(<span class="code-quote">"/content/header"</span>);
%&gt;
    &lt;/div&gt;
    &lt;h1&gt;&lt;%= currentNode.title %&gt;&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div>

<p>And upload it again to replace the previous version:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>curl -u admin:admin -T html.esp http://localhost:8080/apps/foo/bar/html.esp
</pre>
</div></div>

<p>The <a href="http://localhost:8080/content/mynode.html" class="external-link"
rel="nofollow">http://localhost:8080/content/mynode.html</a>, once refreshed, now
shows the blue headline and logo, and this layout also applies to any node created with <em>sling:resourceType=foo/bar</em>.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Discover+Sling+in+15+minutes">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=76179&revisedVersion=33&originalVersion=32">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Discover+Sling+in+15+minutes?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message