<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sightly Archives - Sourced Code</title>
	<atom:link href="https://sourcedcode.com/blog/category/aem/development/sightly/feed" rel="self" type="application/rss+xml" />
	<link>https://sourcedcode.com</link>
	<description>AEM Blog Made Just for You.</description>
	<lastBuildDate>Thu, 01 Aug 2024 06:04:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>

<image>
	<url>https://sourcedcode.com/wp-content/uploads/2019/09/cropped-favicon-32x32.png</url>
	<title>Sightly Archives - Sourced Code</title>
	<link>https://sourcedcode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Understanding `data-sly-attribute` in AEM Sightly (HTL)</title>
		<link>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl</link>
					<comments>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 27 Jun 2024 05:30:13 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=7113</guid>

					<description><![CDATA[<p>The data-sly-attribute directive in HTL (HTML Template Language) allows developers to dynamically set one or more attributes on an HTML element. This powerful feature provides flexibility in managing HTML attributes based on the logic defined in your Sling models or Use classes. Quick Links 1. Element and Attribute Visibility 2. Attribute Value Options 3. Attribute [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl">Understanding `data-sly-attribute` in AEM Sightly (HTL)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <span class="code-highlight-primary">data-sly-attribute</span> directive in HTL (HTML Template Language) allows developers to dynamically set one or more attributes on an HTML element. This powerful feature provides flexibility in managing HTML attributes based on the logic defined in your Sling models or Use classes.</p>
<div class="mention-block">
  <strong>Quick Links</strong></p>
<ul>
<li><a href="#element_and_attribute_visibility">1. Element and Attribute Visibility</a></li>
<li><a href="#attribute_value_options">2. Attribute Value Options</a></li>
<li><a href="#attribute_identifier">3. Attribute Identifier</a></li>
<li><a href="#using_data_sly_attribute">4. Using `data-sly-attribute`</a></li>
<li><a href="#injecting_multiple_attributes">5. Injecting Multiple Attributes</a></li>
<li><a href="#more_examples">6. More Examples</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</div>
<hr class="spacer-larger" />
<h2 id="element_and_attribute_visibility">1. Element and Attribute Visibility</h2>
<p>When using the <span class="code-highlight-primary">data-sly-attribute</span> directive, it&#8217;s important to understand how it affects the visibility of elements and their attributes:</p>
<p><strong>Element Visibility</strong>: The HTML element to which the <span class="code-highlight-primary">data-sly-attribute</span> directive is applied will always be rendered in the DOM. This means that the element itself will always be visible, regardless of the attributes set or not set by the directive.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>p data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'highlight'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;highlight&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>Even if <span class="code-highlight-primary">dynamicClass</span> is empty or undefined, the paragraph will still appear in the DOM.</p>
<p><strong>Element Content</strong>: The content inside the HTML element will also always be displayed. The <span class="code-highlight-primary">data-sly-attribute</span> directive only affects the attributes of the element, not its content. This ensures that the inner content remains intact and visible to the users.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>span data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">id</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicId}&quot;</span><span style="color: #339933;">&gt;</span>Content remains visible.<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicId <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span>Content remains visible.<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>Even if <span class="code-highlight-primary">dynamicId</span> is empty or undefined, the text &#8220;Content remains visible&#8221; will still be displayed within the span element.</p>
<hr class="spacer-larger" />
<h2 id="attribute_value_options">2. Attribute Value Options</h2>
<p>The attribute value in <span class="code-highlight-primary">data-sly-attribute</span> is optional and can be of different types:</p>
<p><strong>String</strong>: Used to set the content of the attribute.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>a data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">href</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicHref}&quot;</span><span style="color: #339933;">&gt;</span>Click here<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicHref <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.example.com'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.example.com&quot;</span><span style="color: #339933;">&gt;</span>Click here<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Boolean</strong>: Used for setting boolean attributes.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">checked</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${isChecked}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming isChecked <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked <span style="color: #339933;">/&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Object</strong>: Used for setting multiple attributes simultaneously.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicDiv'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicDiv&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>If the attribute value is omitted, the attribute will be removed.</p>
<hr class="spacer-larger" />
<h2 id="attribute_identifier">3. Attribute Identifier</h2>
<p>The attribute identifier, which is the name of the attribute, is also optional. It must be omitted only if the attribute value is an Object.</p>
<p><strong>Detailed Explanation:</strong></p>
<p>When using the <span class="code-highlight-primary">data-sly-attribute</span> directive, you can specify the name of the attribute you want to set. This is called the attribute identifier. However, when you are using an Object to set multiple attributes at once, you do not need to specify individual attribute names.</p>
<p><strong>Code Examples:</strong></p>
<p><strong>Specifying Attribute Identifier:</strong></p>
<p>When setting a single attribute, you provide the attribute name directly.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>p data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'highlight'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;highlight&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Omitting Attribute Identifier (Using an Object):</strong></p>
<p>When setting multiple attributes simultaneously, you use an Object and omit the attribute name.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicDiv'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span>, <span style="color: #0000ff;">'aria-label'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'click'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicDiv&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span> aria<span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;click&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>In this case, the keys of the Object (<span class="code-highlight-primary">id</span> and <span class="code-highlight-primary">class</span>) are used as attribute names, and their corresponding values (<span class="code-highlight-primary">dynamicDiv</span> and <span class="code-highlight-primary">dynamicClass</span>) are assigned to those attributes.</p>
<hr class="spacer-larger" />
<h2 id="using_data_sly_attribute">4. Using `data-sly-attribute`</h2>
<p>You can define attributes either directly through an expression or by using a <span class="code-highlight-primary">data-sly-attribute.*</span> attribute. This approach allows designers to annotate HTML without modifying the mock content.</p>
<hr class="spacer-medium" />
<h3 id="example_1_overwriting_an_attribute">Example: Overwriting an Attribute</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;!--</span> <span style="color: #000000; font-weight: bold;">This</span> will overwrite the <span style="color: #000000; font-weight: bold;">class</span> attribute value <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;initialClass&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'newClass'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;newClass&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3 id="example_2_creating_a_new_attribute">Example: Creating a New Attribute</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;!--</span> <span style="color: #000000; font-weight: bold;">This</span> will create a data<span style="color: #339933;">-</span>values attribute <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicValues}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicValues <span style="color: #339933;">=</span> <span style="color: #0000ff;">'exampleValue'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag aria<span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;exampleValue&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="injecting_multiple_attributes">5. Injecting Multiple Attributes</h2>
<p>The <span class="code-highlight-primary">data-sly-attribute</span> block element, when used without specifying an attribute name, allows the injection of multiple attributes that have been prepared in a map object containing key-value pairs.</p>
<hr class="spacer-medium" />
<h3 id="example_3_injecting_multiple_attributes">Example: Injecting Multiple Attributes</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>input data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicId'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicId&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">/&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="more_examples">6. More Examples</h2>
<hr class="spacer-medium" />
<h3 id="example_4_setting_multiple_attributes_on_a_button">Example: Setting Multiple Attributes on a Button</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>button data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${buttonAttributes}&quot;</span><span style="color: #339933;">&gt;</span>Click Me<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming buttonAttributes <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'submitButton'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'btn btn-primary'</span>, <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>button id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submitButton&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;btn btn-primary&quot;</span> disabled<span style="color: #339933;">&gt;</span>Click Me<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3 id="example_5_conditional_attribute_setting">Example: Conditional Attribute Setting</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">target</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${openInNewTab ? '_blank' : ''}&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming openInNewTab <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output <span style="color: #000000; font-weight: bold;">if</span> openInNewTab is <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span> target<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_blank&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;noopener&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Output <span style="color: #000000; font-weight: bold;">if</span> openInNewTab is <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${properties.ariaLabelText}&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a custom aria-label'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;This is a custom aria-label&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">3</span><br />
<span style="color: #339933;">&lt;</span>iframe data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>atribute.<span style="color: #006633;">allowfullscreen</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${properties.isAllowfullscreen}&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>iframe allowfullscreen src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">isAllowfullscreen</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>iframe src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="conclusion">Conclusion</h2>
<p>The <span class="code-highlight-primary">data-sly-attribute</span> directive in HTL provides a versatile way to manage HTML attributes dynamically. Whether you&#8217;re setting a single attribute or multiple attributes at once, this feature can help you create more dynamic and flexible web components. By leveraging <span class="code-highlight-primary">data-sly-attribute</span>, you can ensure that your HTML remains clean and maintainable, while still being able to handle complex attribute logic.</p>
<p>Feel free to explore and use these examples to enhance your AEM projects, making your components more dynamic and interactive.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl">Understanding `data-sly-attribute` in AEM Sightly (HTL)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Official Documentation: Everything You Need to Know</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 31 Jul 2023 06:21:42 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5513</guid>

					<description><![CDATA[<p>This blog particularly promotes Adobe&#8217;s AEM Sightly documentation, which lives inside of their github repository. In this article, we&#8217;ll explore the significance of AEM Sightly and how its official documentation can be a valuable resource for developers working with Adobe Experience Manager. With understanding Adobe&#8217;s Sightly documentation, you will be equipped with the right tools [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know">AEM Sightly Official Documentation: Everything You Need to Know</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This blog particularly promotes Adobe&#8217;s AEM Sightly documentation, which lives inside of their github repository. In this article, we&#8217;ll explore the significance of AEM Sightly and how its official documentation can be a valuable resource for developers working with Adobe Experience Manager. With understanding Adobe&#8217;s Sightly documentation, you will be equipped with the right tools to effectively and efficiently write AEM Sightly code.
</p>
<p>As per this article is written, Sightly is versioned as 1.4. If you wish to find out what version sightly your AEM environment is using, <a href="https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using#:~:text=Visit%20the%20system%20console%20bundles,see%20the%20versions%20being%20used." rel="noopener" target="_blank">you can refer to this article here, which it will explain you how to find out the Sightly Version</a>.</p>
<p>
   If you want to dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</p>
<div class="mention-block">
   <strong>Quick Links</strong></p>
<ol>
<li><a href="#what-is-sightly">What is AEM Sightly?</a></li>
<li><a href="#understanding-documentation">Understanding the Official Documentation</a></li>
<li><a href="#getting-started">Getting Started with AEM Sightly</a></li>
<li><a href="#sightly-syntax">Sightly Syntax and Expressions</a></li>
<li><a href="#templating-features">Templating Language Features</a></li>
<li><a href="#working-with-components">Working with Sightly in AEM Components</a></li>
<li><a href="#best-practices">Best Practices and Tips</a></li>
<li><a href="#extending-sightly">Extending Sightly</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<div id="what-is-sightly">
<h2>1. What is AEM Sightly?</h2>
<p>
      AEM Sightly is a templating language used for building components in Adobe Experience Manager. It offers a clean and efficient way to separate the presentation layer from the business logic, resulting in more maintainable and reusable code.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="understanding-documentation">
<h2>2. Understanding the Official Documentation</h2>
<p>
      The official documentation provided by Adobe for AEM Sightly is a comprehensive guide that covers all aspects of working with Sightly. It is organized into different sections, making it easy to find the information you need.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="getting-started">
<h2>3. Getting Started with AEM Sightly</h2>
<p>
      If you are new to AEM Sightly, the official documentation provides resources to help you get started. You&#8217;ll find step-by-step instructions on setting up your development environment for Sightly projects.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="sightly-syntax">
<h2>4. Sightly Syntax and Expressions</h2>
<p>
      Sightly introduces its own syntax, different from JSP, for creating templates. The documentation explains the Sightly syntax and how expressions are used within templates to dynamically render content.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="templating-features">
<h2>5. Templating Language Features</h2>
<p>
      Sightly offers a range of templating language features like conditionals, loops, and variable declarations. The official documentation provides clear examples and explanations of each feature to help you use them effectively in your projects.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="working-with-components">
<h2>6. Working with Sightly in AEM Components</h2>
<p>
      Learn how to create AEM components using Sightly and integrate them with HTML to build reusable components that enhance the overall user experience.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="best-practices">
<h2>7. Best Practices and Tips</h2>
<p>
      To make the most out of Sightly, the documentation shares best practices for efficient development and tips to avoid common mistakes.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="extending-sightly">
<h2>8. Extending Sightly</h2>
<p>
      For advanced users, the official documentation covers how to extend Sightly by writing custom Java Use-API classes to add additional functionality.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="conclusion">
<h2>Conclusion</h2>
<p>
      AEM Sightly is a powerful templating language that empowers developers in Adobe Experience Manager projects. The official documentation provided by Adobe is an essential resource to understand and leverage the full potential of Sightly in your AEM development journey.
   </p>
<p>
      Throughout this article, we&#8217;ve explored the different aspects of the official documentation and how it can benefit developers. From getting started with Sightly to mastering its templating language features, the documentation acts as a comprehensive guide to help you build robust and efficient AEM components.
   </p>
<p>
      One of the significant advantages of the official documentation is that it is regularly updated by the Adobe team, ensuring that you have access to the latest features and best practices. Additionally, the documentation encourages a collaborative community, where you can contribute and share your insights to improve the experience for all users.
   </p>
<p>
      As you embark on your AEM Sightly development projects, we encourage you to make the most of the official documentation. By referring to it as your go-to resource, you&#8217;ll be equipped with the knowledge and skills needed to create outstanding experiences with Adobe Experience Manager.
   </p>
<p>
      Now that you know where to find the official documentation, dive in, explore, and take advantage of this invaluable resource. Whether you are a beginner or an experienced developer, the AEM Sightly official documentation will undoubtedly be your trusted companion on your journey to building exceptional AEM components.
   </p>
<p>
      Thank you for reading our blog article, and we hope it has inspired you to leverage AEM Sightly&#8217;s capabilities to create amazing digital experiences!
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know">AEM Sightly Official Documentation: Everything You Need to Know</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM RichText Remove P Tag on Sightly</title>
		<link>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly</link>
					<comments>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 29 Jul 2023 03:29:27 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5365</guid>

					<description><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly">AEM RichText Remove P Tag on Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the p single paragraph container tag. However, I have spent some time and found a very lucrative solution. Lets remove the p tag from the rich text editor!</p>
<p>In this article, we will step through my implementation for us to remove the p tag once and for all, from being rendered. </p>
<p>My solution to this problem will be dealt with in the backend, Sling Model. Some may argue that the solution can be done using Javascript, but that can be very troublesome. Let&#8217;s Keep it Simple Stupid (KISS). There&#8217;s one caveat to this approach; scroll to the bottom of the page to see what it is.</p>
<p>Follow my 3 steps below to remove the P tag wrapper from what is being produced by the cq/gui/components/authoring/dialog/richtext.</p>
<p><iframe width="560" height="315" src="https://www.youtube.com/embed/WSS1Tfau4dc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<hr class="spacer-large"/>
<h3>Step 1. Add Custom Option In the Paraformat Options</h3>
<p>Under the _cq_dialog.xml, <strong>cq/gui/components/authoring/dialog/richtext</strong>, add a new format option under the paraformat list of options. </p>
<p>The selected paraformat option will be a custom HTML element that wraps onto the highlighted or selected text from the author. In this case, when the author have selected text, and then click on the new paraformat option, the Html will look something like this <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
// the complete _cq_dialog.xml configuration for the cq/gui/components/authoring/dialog/richtext<br />
// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/richtext&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./text&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">useFixedInlineToolbar</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rtePlugins</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;format</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;bold,italic&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;links</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;modifylink,unlink&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;formats</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_p</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Paragraph&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h1</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 1&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h2</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 2&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h3</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 3&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h4</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 4&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h4&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h5</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 5&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h6</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 6&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h6&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_blockquote</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Quote&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;blockquote&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_pre</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Preformatted&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;pre&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/formats<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paraformat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rtePlugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uiSettings</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cui</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inline</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">toolbar</span>=<span style="color: #ff0000;">&quot;[format#bold,format#italic,format#underline,#justify,#lists,links#modifylink,links#unlink,#paraformat]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;popovers</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[justify#justifyleft,justify#justifycenter,justify#justifyright]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;justify&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[lists#unordered,lists#ordered,lists#outdent,lists#indent]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;paraformat:getFormats:paraformat-pulldown&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paraformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/popovers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inline<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cui<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uiSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 2. Create the Backend, Sling Model, to Text Transform</h3>
<p>The backend Sling Model will read the ./text property that has been set by the user&#8217;s input. Using the String.ReplaceAll(), we can replace all <span class="code-highlight-secondary">&lt;/?notextformat&gt;</span>, regex pattern, with nothing (meaning that this element will be removed).</p>
<p>For example <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>. -> <span class="code-highlight-primary">sometext</span>.</p>
<p>We next save the formatted text into a variable of <span class="code-highlight-secondary"richText</span>, which can be used by sightly to display HTML on the page.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Default</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Optional</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ValueMapValue</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables<span style="color: #339933;">=</span>Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyTextComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Optional<br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; @<span style="color: #000000; font-weight: bold;">Default</span><span style="color: #009900;">&#40;</span>values <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> text<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> richText<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>text.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richText <span style="color: #339933;">=</span> text.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/?notextformat&gt;&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getRichText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> richText<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 3. Render Text Transform from Sightly</h3>
<p>Now finally we just need to utilise sightly to print the text transformed, <span class="code-highlight-primary">richText</span>, to the screen.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;sly data-sly-use.myTextComponent<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.MyTextComponent&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
${myTextComponent.richText @ context='html'}<br />
<span style="color: #009900;">&lt;sly data-sly-use.templates<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-call<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${templates.placeholder @ isEmpty = !myTextComponent.richText}&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<div class="mention-block">
<strong>Last Thoughts?</strong><br />
The caveat with this approach is that when you are trying to export JSON format from this component, you will be stuck with this block of text, <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>, unless if you text to transform the export as well.</p>
<p>The reason why I did not overwrite the JCR values is that I wanted to retain the natural editing experience for the authors. With my solution when the author decides to make changes to the rich text field, they would not have a werid experience.
</p></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly">AEM RichText Remove P Tag on Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Component(s) Empty CQ PlaceHolder</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 25 Feb 2023 21:55:28 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4453</guid>

					<description><![CDATA[<p>In almost all cases, component&#8217;s that are not configured, dragged onto the page should have some sort of indicator telling content authors that they should configure the component; a few of us calls this the empty component placeholder or &#8220;cq-placeholder&#8221;. A novice AEM full-stack may not be geared with the right tools, and so they [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder">AEM Sightly Component(s) Empty CQ PlaceHolder</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In almost all cases, component&#8217;s that are not configured, dragged onto the page should have some sort of indicator telling content authors that they should configure the component; a few of us calls this the empty component placeholder or &#8220;cq-placeholder&#8221;. A novice AEM full-stack may not be geared with the right tools, and so they add unnecessary Sightly HTL code into the .html file, and try to create this indicator experience. Let&#8217;s not re-create the wheel. There&#8217;s actually an Adobe way to create the &#8220;placeholder&#8221; AEM component experience. This is using the Adobe WCM Core Component&#8217;s &#8220;core/wcm/components/commons/v1/templates.html” script; what exactly is the &#8220;core/wcm/components/commons/v1/templates.html”?</p>
<p>In the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe Core Component&#8217;s Library</a>, you will be able to find this particular file &#8220;<a href="https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/commons/v1/templates.html" rel="noopener" target="_blank">core/wcm/components/commons/v1/templates.html</a>&#8220;. This file is a template that renders an HTML element on the page with the &#8220;cq-placeholder&#8221; cssClass that makes the rendered element on the page look something like this.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img fetchpriority="high" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<p>When we inspect the <a href="https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/commons/v1/templates.html" rel="noopener" target="_blank">Adobe code</a>, you will see the sightly HTL code as like this:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>template.<span style="color: #006633;">placeholder</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${@ isEmpty, classAppend, emptyTextAppend}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>test<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${(wcmmode.edit || wcmmode.preview) &amp;&amp; isEmpty}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq-placeholder ${classAppend}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>emptytext<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${component.properties.jcr:title}${emptyTextAppend &amp;&amp; ' - '}${emptyTextAppend}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>We understand that we are using Sightly HTL Version: 1.4; where this version enables the feature &#8220;template &#038; calls&#8221;, and templates. From the code above, you can see that &#8220;core/wcm/components/commons/v1/templates.html&#8221; is a Sightly template, and its main purpose is to be called via &#8220;data-sly-use&#8221;. Line-1: This template accepts 3 parameters: isEmpty, classAppend, emptyTextAppend. Line-2: This template is declaring a new div, and <span style="color: red;">only rendered when (edit or preview mode) and isEmpty = true</span>. Line-3: This appends the cq-placeholder cssClass for this &lt;div&gt;, and include custom ${classAppend} if exists. Finally Line-4: renders the resource&#8217;s component.properties.jcr:title (component who calls this script) on the screen, and also appends ${emptyTextAppend} to the cq-placeholder&#8217;s text if present.</p>
<div class="mention-block">
<strong>core/wcm/components/commons/v1/templates.html accepts 3 parameters:</strong></p>
<ul>
<li>isEmpty: This value must be a boolean, which true will force the cq-template to appear.</li>
<li>classAppend: This value must be a string, where it will be appended to the rendered HTML cq-placeholder.</li>
<li>emptyTextAppend: This value must be a string, where text will be appended into the cq-placeholder.</li>
</ul>
</div>
<hr class="spacer-larger" />
<h2>Examples:</h2>
<p>&nbsp;</p>
<h3>1. Basic call example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, you can see us calling the Sling Model backend &#8220;com.sourcedcode.core.components.models.Teaser&#8221;, and capturing the Sling Model in a &#8220;model&#8221; variable. Line-3, we understand that the templates.html is accepting the &#8220;isEmpty&#8221; parameter. The &#8220;isEmpty&#8221; parameter is evaluated with &#8220;!model.titleText&#8221; (this means if the model.titleText is empty or null it will return true). When &#8220;isEmpty&#8221; is true, then the cq-placeholder will be rendered, and if false. It will never be rendered.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!model.titleText}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img fetchpriority="high" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<hr class="spacer-larger" />
<h3>2. Second example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, Line-3, you will notice that model.titleText &#038;&#038; model.descriptionText are being evaluated, and must not be null or empty. If the evaluation of isEmpty is true, cq-placeholder will be visible.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!(model.titleText &amp;&amp; model.descriptionText)}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img fetchpriority="high" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<hr class="spacer-larger" />
<h3>3. Third example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, Line-3, notice that we are using other parameters to construct the cq-placeholder; classAppend, where we are passing in cmp-teaser as a customCSSClass. Line-4, we are utilizing the parameter, emptyTextAppend, where we can add custom description to the cq-placeholder. The expected behavior here is, when the evaluation of isEmpty is true, we expect to see the rendered cq-placeholder with some description test. See the screenshot below for an example.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!(model.titleText &amp;&amp; model.descriptionText), classAppend='cmp-teaser', <br />
&nbsp; &nbsp; &nbsp;emptyTextAppend='This component must be configured'}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html with custom description" width="1070" height="328" class="alignnone size-full wp-image-4468" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png 1070w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-300x92.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-1024x314.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-768x235.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-600x184.png 600w" sizes="(max-width: 1070px) 100vw, 1070px" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder">AEM Sightly Component(s) Empty CQ PlaceHolder</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create System &#124; Service Users in AEM 6.5 with Code Configurations</title>
		<link>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations</link>
					<comments>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 27 Nov 2022 00:35:46 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4026</guid>

					<description><![CDATA[<p>In this article we will walk through how to configure your AEM project to have the AEM environment self configure System Users in AEM with code, so that you would not need to do it the manual way. With the leverage of the org.apache.sling.jcr.api v2.4.0 bundle provided by AEM 6.5.4+ or AEM as a Cloud [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">Create System | Service Users in AEM 6.5 with Code Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article we will walk through how to configure your AEM project to have the AEM environment self configure System Users in AEM with code, so that you would not need to do it the <a href="https://experienceleague.adobe.com/docs/experience-manager-65/administering/security/security-service-users.html?lang=en" rel="noopener" target="_blank">manual way</a>. </p>
<p>With the leverage of the org.apache.sling.jcr.api v2.4.0 bundle provided by <strong>AEM 6.5.4+</strong> or <strong>AEM as a Cloud Service</strong>, we are able to utilize the Repository Initialization (repoinit) feature. At the start of this article, we will quickly provide a review of what a system user is, next we will explain what actually is the Repository Initialization (repoinit) feature and it&#8217;s dependencies, and finally, we will be providing some code examples on how to setup this feature on your own AEM instance with a code follow through.</p>
<p>AEM System Users are also referred as Service Users.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#aem-system-user-quick-review" rel="noopener">AEM System User Quick Review</a></li>
<li><a href="#what-is-repository-initialization-repoinit" rel="noopener">What Is Repository Initialization (repoinit)?</a></li>
<li><a href="#aem-dependencies-for-the-repository-initialization-feature-sling-repo-init">AEM Dependencies for the Repository Initialization Feature(Sling RepoInit)</a></li>
<li><a href="#code-follow-through">Code Follow Through</a>
<ul>
<li><a href="#configure-org-apache-sling-jcr-repoinit-repository-initializer-pid">A. Configure org.apache.sling.jcr.repoinit.RepositoryInitializer PID</a></li>
<li><a href="#configure-org-apache-sling-serviceusermapping-impl-service-user-mapper-impl-amended-pid">B. Configure org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended PID</a></li>
<li><a href="#register-basic-servlet-get-request">C. Register Basic Servlet (GET Request)</a></li>
<li><a href="#test-and-validate-the-servlet-response">D. Test and Validate the Servlet Response</a></li>
<li><a href="#service-user-in-user-admin">E. ServiceUser in UserAdmin</a></li>
</ul>
</li>
</ol>
</div>
<hr class="spacer-large"/>
<h3 id="aem-system-user-quick-review">1. AEM System User Quick Review</h3>
<p>Before we begin, let&#8217;s reiterate what a System User in AEM is. A system user is a JCR user with no password set and a minimal set of privileges that are necessary to perform a specific task. Having no password set means that it will not be possible to login with a system user. A system user is typically utilized by the AEM backend code which have privileges to create, read, update, and delete nodes in the JCR; the backend code will authenticate as a system user as a session when needed, and is required to session logout right when the task or tasks have been completed. Not logging out of a system user from the AEM backend will cause issues. If you do not logout of a session that you have opened, your AEM will be flooded by opened sessions, your AEM will start complaining with *INFO* [Apache Sling Resource Resolver Finalizer Thread] org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl Unclosed ResourceResolver, and eventually your AEM environment will run out of memory and crash; to learn more about this topic, take a look at this blog article, <a href="https://cqdump.joerghoh.de/2018/11/12/resourceresolvers-and-sessions-you-open-it-you-close-it/" rel="noopener" target="_blank">ResourceResolvers and Sessions — “you open it</a>, you close it”, by Jörg Hoh. The rule of thumb for creating System Users is to keep the privileges very specific; ensure you have a plan for this system user.</p>
<hr class="spacer-large"/>
<h2 id="what-is-repository-initialization-repoinit">2. What Is Repository Initialization (repoinit)?</h2>
<p>Sling RepoInit is a mechanism that allows configuration code to run before the SlingRepository service is registered. Configuration code is registered under the org.apache.sling.jcr.repoinit.RepositoryInitializer factory PID, and written in a mini-language.</p>
<p>The org.apache.sling.repoinit.parser implements a mini-language meant to create paths, system users and manage access control in a content repository, as well as registering JCR namespaces, node types and privileges. Defining access control content consists of setting and deleting policies of type access control lists (ACL) for which individual access control entries (ACE) can be added and removed.</p>
<p>Full documentation found <a href="https://sling.apache.org/documentation/bundles/repository-initialization.html" rel="noopener" target="_blank">here</a>.</p>
<hr class="spacer-large"/>
<h2 id="aem-dependencies-for-the-repository-initialization-feature-sling-repo-init">3. AEM Dependencies for the Repository Initialization Feature(Sling RepoInit)</h2>
<p>To be able to use this feature, you must have <strong>AEM 6.5.4+</strong> or <strong>AEM as a Cloud Service</strong>.</p>
<p>From out of the box AEM 6.5, it already includes a version of Sling RepoInit, but this is likely an older version without the service pack. If you are not able to replicate the <a href="#code-follow-through">code follow through</a> mentioned on this article, consider upgrading your AEM service pack to the supported version <strong>AEM 6.5.4+</strong>. Take a look at my bundle versions found in /system/console/bundles (as these installed versions are working as expected on my machine):</p>
<ul>
<li>org.apache.sling.jcr.api @ 2.4.0</li>
<li>org.apache.sling.jcr.repoinit @ 1.1.28</li>
<li>org.apache.sling.repoinit.parser @ 1.6.2</li>
</ul>
<hr class="spacer-larger"/>
<h2 id="code-follow-through">4. Code Follow Through</h2>
<p>In the code follow through, you will create a system user with code configurations. Next, with the system user, you will write code for a simple AEM Servlet which will be a GET request, which will write a new property into an existing node in AEM.</p>
<hr class="spacer-large"/>
<h3 id="configure-org-apache-sling-jcr-repoinit-repository-initializer-pid">A. Configure org.apache.sling.jcr.repoinit.RepositoryInitializer PID</h3>
<p>With the org.apache.sling.jcr.repoinit.RepositoryInitializer factory PID, we will be creating a new configuration file.</p>
<p>With this configuration, we are creating a system user named sourcedCodeSystemUser, and will be placed into the folder structure of /home/users/system/sourcedCode. The system user, sourcedCodeSystemUser, will have ACL (Access Control List) privileges configured to:</p>
<ul>
<li>allow read,write,replicate for all JCR resources which exists under /content/sourcedcode</li>
<li>allow read,write,replicate for all JCR resources which exists under /conf/sourcedcode</li>
<li>allow ALL-CRUD-ACTIONS for all JCR resources which exists under /content/we-retail</li>
</ul>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.config</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">scripts=[&quot;<br />
&nbsp; &nbsp; create service user sourcedCodeSystemUser with path /home/users/system/sourcedCode<br />
&nbsp; &nbsp; set ACL for sourcedCodeSystemUser<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /content/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /conf/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:all on /content/we-retail<br />
&nbsp; &nbsp; end<br />
&quot;]</div></td></tr></tbody></table></div>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.cfg.json</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066;">scripts</span>=<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<br />
&nbsp; &nbsp; create service user sourcedCodeSystemUser with path /home/users/system/sourcedCode<br />
&nbsp; &nbsp; set ACL for sourcedCodeSystemUser<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /content/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /conf/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:all on /content/we-retail<br />
&nbsp; &nbsp; end<br />
&quot;</span><span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<p>Such configurations have two optional fields:<br />
A multi-value <strong>references</strong> field with each value providing the URL (as a String) of raw repoinit statements.<br />
A multi-value <strong>scripts</strong> field with each value providing repoinit statements as plain text in a String.</p>
<hr class="spacer-large"/>
<h3 id="configure-org-apache-sling-serviceusermapping-impl-service-user-mapper-impl-amended-pid">B. Configure org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended PID</h3>
<p>To add a mapping from your service to the corresponding System Users you need to create a factory configuration for the [ServiceUserMapper](https://sling.apache.org/apidocs/sling7/org/apache/sling/serviceusermapping/ServiceUserMapper.html) service. To keep this modular such configurations can be provided using the Sling amend mechanism. </p>
<p>Below, you will see us mapping the sourcedcode.core backend to the sourcedCodeSystemUser.</p>
<p>filename: org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-sourcedcodeSystemUser.config</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066;">user.mapping</span>=<span style="color: #66cc66;">&#91;</span> \<br />
&nbsp; <span style="color: #ff0000;">&quot;sourcedcode.core:sourcedCodeSystemUser\=[sourcedCodeSystemUser]&quot;</span><br />
<span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3 id="register-basic-servlet-get-request">C. Register Basic Servlet (GET Request)</h3>
<p>line:38, we are creating the Map<String, Object> authInfo class with ResourceResolverFactory.SUBSERVICE set to the system user that we have just created, &#8220;sourcedCodeSystemUser&#8221;.</p>
<p>line:41, we will utilize the Java 7 API, “try-wth-resource”, best practice, to ensure that when we open a new session, we are never forgetting to close the session after the use of it; Since Sling9 (roughly 2016) the ResourceResolver interface implements the AutoCloseable marker interface, so the try-with-resource idiom can be used. Here we are obtaining the resolver via ResourceResolverFactory.getServiceResourceResolver() method.</p>
<p>line:42, we are adapting the resolver into a javax.jcr.Session.class.</p>
<p>line:44-50, we are getting the AEM JCR node, writing new properties to /content/sourcedcode/jcr:content, and replicating the node. And on succeess, we will return the message of &#8220;Test is saved and replicated&#8221;.</p>
<p><strong>filename</strong>: sourcedcode/core/src/main/java/com/sourcedcode/core/servlets/SimpleGetServlet.java</p>
<div class="code-750">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.replication.ReplicationActionType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.replication.Replicator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolverFactory</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.HttpConstants</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Objects</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/simple-get&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=&quot;</span> <span style="color: #339933;">+</span> HttpConstants.<span style="color: #006633;">METHOD_GET</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleGetServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolverFactory factory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Replicator replicator<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest req, <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Session session <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node contentNode <span style="color: #339933;">=</span> session.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Objects.<span style="color: #006633;">nonNull</span><span style="color: #009900;">&#40;</span>contentNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span>, <span style="color: #0000ff;">&quot;works&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; replicator.<span style="color: #006633;">replicate</span><span style="color: #009900;">&#40;</span>session, ReplicationActionType.<span style="color: #006633;">ACTIVATE</span>, contentNode.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test is saved and replicated.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to save.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<h4>D. Test and Validate the Servlet Response</h3>
<p>Now use your maven skills to build the project!</p>
<p>Next, after a successful build, you would want to make a call to your AEM servlet, via <a href="http://localhost:4502/bin/simple-get" rel="noopener" target="_blank">http://localhost:4502/bin/simple-get</a>. With the service system successfully configured in your environment, you should be able to see a successful message.</p>
<p><strong>Test is saved and replicated.</strong></p>
<p>Revealing the changes in the JCR content, <a href="http://localhost:4502/crx/de/index.jsp#/content/sourcedcode/jcr%3Acontent" rel="noopener" target="_blank">http://localhost:4502/crx/de/index.jsp#/content/sourcedcode/jcr%3Acontent</a>, you should be able to see the changes.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png" alt="Screenshot of the crx/de properties for the JCR node, /content/sourcedcode/jcr%3Acontent" width="3840" height="2070" class="alignnone size-full wp-image-4065" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png 3840w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-300x162.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-1024x552.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-768x414.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-1536x828.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-2048x1104.png 2048w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-600x323.png 600w" sizes="(max-width: 3840px) 100vw, 3840px" /></a></p>
<hr class="spacer-large"/>
<h4 id="service-user-in-user-admin">E. ServiceUser in UserAdmin</h3>
<p>If you like, take a look at <a href="http://localhost:4502/useradmi" rel="noopener" target="_blank">http://localhost:4502/useradmin</a>. Search for the sourcedcodeSystemUser and review the permissions for this system user. You should be able to see permissions reflected for this system user:</p>
<ul>
<li>allow read,write,replicate for all JCR resources which exists under /content/sourcedcode</li>
<li>allow read,write,replicate for all JCR resources which exists under /conf/sourcedcode</li>
<li>allow ALL-CRUD-ACTIONS for all JCR resources which exists under /content/we-retail</li>
</ul>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png" alt="In the AEM useradmin console, showcasing the sourcedcodeSystemUser with correct permissions." width="100%" height="2067" class="alignnone size-full wp-image-4061" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png 3835w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-300x162.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-1024x552.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-768x414.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-1536x828.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-2048x1104.png 2048w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-600x323.png 600w" sizes="(max-width: 3835px) 100vw, 3835px" /></a></p>
<hr class="spacer-large"/>
<h3>This article covers questions like</h3>
<ul>
<li>How to create AEM System User Programmatically</li>
<li>How to create AEM System User Automatically</li>
<li>How to create AEM System User on AEMaaCS</li>
<li>How to create AEM System User with Code</li>
<li>How to create AEM System User that is not manual</li>
<li>How to create AEM System User the preferred way</li>
<li>How to create AEM Service User Programmatically</li>
<li>How to create AEM Service User Automatically</li>
<li>How to create AEM Service User on AEMaaCS</li>
<li>How to create AEM Service User with Code</li>
<li>How to create AEM Service User that is not manual</li>
<li>How to create AEM Service User the preferred way</li>
</ul>
<hr class="spacer-large"/>
<h3>Path not found by AEMaaCS</h3>
<p>Sometimes you may find errors in the AEMaaCS pipelines due to the reason that when reference to path that you are allowing system user permissions to, path does not exist. And so, the node must declare creation of these path&#8217;s in the repo-init script. Although the path&#8217;s are already installed inside of AEM, it wouldn&#8217;t do anything anyways&#8230; this is to fix the repo-init system user pipeline errors.</p>
<p>Here&#8217;s an example of us creating a repo-init system user which allows permissions for the system user, and includes the creation of paths:</p>
<ul>
<li>allow jcr:all on /content/sourcedcode</li>
<li>allow jcr:all on /conf/sourcedcode</li>
<li>allow jcr:all on /content/dam/sourcedcode</li>
<li>allow jcr:all on /content/cq:tags/sourcedcode</li>
</ul>
<h3>repoinit cfg json example for creating system user</h3>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.cfg.json</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;scripts&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (sling:OrderedFolder) /content/dam/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (nt:unstructured) /content/dam/sourcedcode/jcr:content&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:Page) /content/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:PageContent) /content/sourcedcode/jcr:content&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (sling:Folder) /conf/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:Tag) /content/cq:tags/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set properties on /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set jcr:title{String} to &quot;</span>Sourced Code<span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set properties on /content/dam/sourcedcode/jcr:content<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set cq:conf{String} to /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set jcr:title{String} to &quot;</span>Sourced Code<span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create service user sourcedcodeSystemUser with path /home/users/system/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set ACL for sourcedcodeSystemUser <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/dam/sourcedcode<span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/cq:tags/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">Create System | Service Users in AEM 6.5 with Code Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Comments with Examples</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 20 Oct 2022 01:58:54 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3868</guid>

					<description><![CDATA[<p>When writing comments in your Sightly HTL file, it&#8217;s best practice not to use HTML comments, but to use the sightly, HTML Template Language. 1. HTL comments are not evaluated and returned back as an empty string in the server-side rendered results. This is best practice when developers are including some comments for other developers [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples">AEM Sightly Comments with Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When writing comments in your Sightly HTL file, it&#8217;s best practice not to use HTML comments, but to use the sightly, HTML Template Language.</p>
<p><strong>1. HTL comments are not evaluated and returned back as an empty string in the server-side rendered results.</strong></p>
<p>This is best practice when developers are including some comments for other developers in their organization.</p>
<p>Sightly HTL comments combine HTML and JavaScript multi-line comments: &lt;!&#8211;/* */&#8211;&gt;</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!--<span style="color: #66cc66;">/</span>* The <span style="color: #000066;">content</span> of this comment will be removed from the output. *<span style="color: #66cc66;">/</span>--&gt;<br />
<span style="color: #66cc66;">//</span> output: <span style="color: #ff0000;">&quot;&quot;</span><br />
<br />
&lt;!--<span style="color: #66cc66;">/</span>* <br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output. <br />
&nbsp; &nbsp; &nbsp; Page <span style="color: #000066;">title</span>: $<span style="color: #66cc66;">&#123;</span>currentPage.jcr:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#125;</span><br />
*<span style="color: #66cc66;">/</span>--&gt;<br />
<span style="color: #66cc66;">//</span> output: <span style="color: #ff0000;">&quot;&quot;</span></div></td></tr></tbody></table></div>
<p><strong>2. Standard HTML comments, the comments are evaluated and are server-side rendered with the expected results.</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!-- Page <span style="color: #000066;">title</span>: $<span style="color: #66cc66;">&#123;</span>currentPage.jcr:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#125;</span> --&gt;<br />
<br />
<span style="color: #66cc66;">//</span>output &lt;!-- Page <span style="color: #000066;">title</span>: Home Page --&gt;</div></td></tr></tbody></table></div>
<p>Available for HTML Template Language Specification 1.4<br />
Release Date: 18 June 2018<br />
Reference: <a href="https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md" rel="noopener" target="_blank">https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md</a> </p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples">AEM Sightly Comments with Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Granite UI Multifield Sightly Traverse &#124; Iterate Simple Example</title>
		<link>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example</link>
					<comments>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 24 Jun 2022 01:58:27 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3526</guid>

					<description><![CDATA[<p>In this article, we will share an example on on how we can iterate and traverse through multifield nodes that have been generated by the Touch UI using Sightly in a very simple way. Going through this article, we will be setting up multifield Granite UI links (as if we are building a menu navigation). [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example">Granite UI Multifield Sightly Traverse | Iterate Simple Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will share an example on on how we can iterate and traverse through multifield nodes that have been generated by the Touch UI using Sightly in a very simple way.</p>
<p>Going through this article, we will be setting up multifield Granite UI links (as if we are building a menu navigation). Each link will define it&#8217;s own path, label, and target. Take a look at both screenshots below. One screenshot indicates how a multifield Granite UI field will look like, and in the second screenshot displays how saved nodes would look like in the crx/de console.</p>
<p><a class="foobox fbx-instance fbx-link" href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-1-1.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-1-1.png" alt="Touch UI - show casing multifield link configurations screenshot" /></a><br />
<a  class="foobox fbx-instance fbx-link"  href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-2.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-2.png" alt="CRX/DE saved link nodes from the Touch UI screenshot" /></a></p>
<hr class="spacer-large"/>
<h3>Step 1. Touch UI Configuration</h3>
<p>Putting together a very basic Touch UI configuration using tabs to organize our Granite UI fields. Here we will place the entire configuration under:<br />
<strong>/apps/sourcedcode/components/content/multilistexample/_cq_dialog/.content.xml</strong>. </p>
<p>line: 34, declaring a multifield<br />
line: 42, declaring multifield > label<br />
line: 48, declaring multifield > path<br />
line: 55, declaring multifield > target</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Multi List Example&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/layouts/tabs&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;nav&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generalSettings</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;General Settings&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/section&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/layouts/fixedcolumns&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;nav&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkOptions</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Links Options&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/fieldset&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;links</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/multifield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">composite</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Links&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./links&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkLabel</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Label&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkLabel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkPath</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/pathfield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Path&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkPath&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">rootPath</span>=<span style="color: #ff0000;">&quot;/content&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkTarget</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Target&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkTarget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;self</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">selected</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Same Page&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_self&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;blank</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;New Tab&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_blank&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkTarget<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/links<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkOptions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generalSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jcr:root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 2. Sightly HTL Front-end</h3>
<p>A very simple way to get a list of objects to iterate through will be to use Sling Model&#8217;s backend and Sling Specific Annotations. Together the mechanism combined will enable the Sightly HTL code to receive a List<Resource>, which you can use this list to iterate through each item, to display nav link configurations that were set by the authors.</p>
<p>Using the Sightly <strong>data-sly-list</strong> API, we can traverse through each item from the List<Resources>. Iterating through each item returns an Resource.class onbject, which it has a getValueMap() public getter method. With this getter method we can get the valueMap object and reveal the configurations that are set by the authors.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-multilistexample&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.cmp<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.content.MultiListExample&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;sly data-sly-list.<span style="color: #000066;">link</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${cmp.links}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${link.valueMap.linkPath}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${link.valueMap.linkTarget}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span>${link.valueMap.linkLabel}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sly&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 3. Sling Model Java Backend</h3>
<p>Sling Model&#8217;s backend and Sling Specific Annotations. Together the mechanism combined will enable the Sightly HTL code to receive a List<Resource>.</p>
<div class="mention-block">
<strong>Pro Tip:</strong><br />
<strong>Decrease your AEM development time using our AEM Sling Model Cheat Sheet Reference Guide! <a href="https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide" rel="noopener" target="_blank">View Guide</a></strong>.
</div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models.content</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ChildResource</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MultiListExample <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;links&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> links<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 4. Results</h3>
<p>Work your maven magic, and build the code. Once your backend bundle and Sightly HTL code are aligned, you should be able to see the links like here in the screenshot.<br />
<a class="foobox fbx-instance fbx-link"  href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-3.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-3.png" alt="Links Results" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example">Granite UI Multifield Sightly Traverse | Iterate Simple Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>HTL Java Use-API Code Example</title>
		<link>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example</link>
					<comments>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 21 Jun 2022 22:49:32 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3473</guid>

					<description><![CDATA[<p>The HTML Template Language (HTL) Java Use-API allows an HTL file to use data-sly-use to access helper functions in a custom Java class. This allows any sophisticated business logic to be wrapped in Java code, while the HTL code is just responsible for direct markup generation. A simple POJO can be used as a Java [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-java-use-api-code-example">HTL Java Use-API Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The HTML Template Language (HTL) Java Use-API allows an HTL file to use data-sly-use to access helper functions in a custom Java class. This allows any sophisticated business logic to be wrapped in Java code, while the HTL code is just responsible for direct markup generation.</p>
<p>A simple POJO can be used as a Java Use-API object, which is instantiated by a specific implementation using the POJO&#8217;s default constructor.</p>
<p>In this article, you will find an example of how the Java Use-API can be bind with a component in AEM. In detail, we will be associating the Java Use-API with the header component.</p>
<hr class="spacer-large">
<h2>Java Use-API Example Code</h2>
<h4>Step 1</h4>
<p>We will place a small little snippet from lines:2-4 which will bind into the simple POJO; inside of the given component,<br />
<strong>/apps/sourcedcode/components/structure/header/header.html</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> data-sly-use.header<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;HeaderJavaUseExample&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>${header.path}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">&lt;!--/* header Sightly HTL code implementation below */--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium">
<h4>Step 2</h4>
<p>We will create a simple Java POJO under,<br />
<strong>/apps/sourcedcode/components/structure/header/HeaderJavaUseExample.java</strong></p>
<p>Taking a look closer, line:1 has the package that is the same path as the targeted component.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">apps.sourcedcode.components.structure.header</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMUsePojo</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HeaderJavaUseExample <span style="color: #000000; font-weight: bold;">extends</span> WCMUsePojo <span style="color: #009900;">&#123;</span><br />
<br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getPath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;This is an example path&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium">
<h4>Step 3</h4>
<p>The Java Pojo extends the WCMUsePojo which makes available all the Global Objects in this naming convention:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">getComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getComponentContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentDesign<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentNode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentStyle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getDesigner<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getEditContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getOut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getPageManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResourceDesign<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResourcePage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getSling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getSlyWcmHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getWcmmode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getXssAPI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-java-use-api-code-example">HTL Java Use-API Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Generate Unique AEM Component ID with Confidence</title>
		<link>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 03 Apr 2022 04:24:28 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3518</guid>

					<description><![CDATA[<p>You frequently require a special ID for the AEM component. Either a backend server-side call or a custom JS action trigger are required. If the component is dragged and placed on the page more than once, the hard-coded field ID is not guaranteed to be unique. When considering ID, you might consider directly using the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence">How to Generate Unique AEM Component ID with Confidence</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You frequently require a special ID for the AEM component. Either a backend server-side call or a custom JS action trigger are required. If the component is dragged and placed on the page more than once, the hard-coded field ID is not guaranteed to be unique. </p>
<p>When considering ID, you might consider directly using the global HTL objects and getters, such as ${currentNode.name}. If the component is used in other containers on the same page, this will not, however, fix the issue. Despite the fact that the JCR node level API produces a distinct id for the current node, the id also includes the node path and forward slashes, exposing the internal content structure and making it challenging to utilize in CSS and JS without escaping.</p>
<p>The id element is made simple to use by CSS and JS by the hash code, which also encapsulates and hides internal path information from the end-user. The developer passes in the ID prefix to make the ID property easier for humans to read. Example code of a Java Sling Model class is provided below. </p>
<div class="mention-block--gold">
<strong>Note</strong>: Please note that this blog article was created in 2022, and so, preferred to create the id is via extending the AbstractComponentImpl object, which provides you the getId method. This method will be the best practice while trying to generate an id for your component. Example code can be found here -> <a href="https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TitleImpl.java#L21" rel="noopener" target="_blank">https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TitleImpl.java#L21</a>
</div>
<hr class="spacer-large"/>
<h3>Sightly</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;sly data-sly-use.componentId<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.utils.ComponentId&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;<br />
&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${componentId.id}&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;<br />
<br />
<span style="color: #66cc66;">//</span> this produces<br />
&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmpheader3901793341&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h3>Java Sling Model</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models.utils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ComponentId <span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp; @ScriptVariable<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Component</span> component<span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; @SlingObject<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> component.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h3>Last Thoughts</h3>
<p>You can improve this setup by adding an &#8220;advanced&#8221; tab in the component&#8217;s Touch UI dialog to have authors insert their own custom component ID. If the author&#8217;s configuration is empty, this mechanism will be kicked in to use the ComponentId Sling Model to generate the Ids.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;sly data-sly-use.componentId<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.utils.ComponentId&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${properties.customComponentId || componentId.id}&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<br />
// this produces<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmpheader3901793341&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence">How to Generate Unique AEM Component ID with Confidence</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
