Hi All,
I am using the reference component in AEM6.4. I have added the reference component in my header.html file. Whenever first time I am going to open the header.html page it will open the page with this component and I need to author the reference path in it, can I add default path in this component, so whenever author will open the page first time, then component will populate with default values in the path section. I have tried with "value" and defaultValue" property on node level but nothing is working. Please suggest.
<div class="contain">
<sly data-sly-resource="${'prelogin' @ resourceType='/apps/project/components/content/reference'}"></sly>
</div>
Regards,
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
You can write a servlet which query site to looks for pages which doesn't have prelogin and add prelogin node with default property using java API
SQL2 Query could be like below:
SELECT * FROM [cq:Page] AS s where isdescendantnode([/content/mfHTL63]) and s.[jcr:content/sling:resourceType] like '%mfHTL63/components/structure/page%' and s.[jcr:content/prelogin/sling:resourceType] not like '%mfHTL63/components/content/reference%'
Servlet Example
aem63app-repo/SimpleSQL2SearchServlet.java at master · arunpatidar02/aem63app-repo · GitHub
Node API example
final NodeIterator result = query.execute().getNodes();
while(result.hasNext()){
Node node=result.nextNode().getChild("jcr:content").addNode("prelogin", "nt:unstructured");
node.setProperty("reference", "/content/mfHTL63/en/jcr:content/header");
}
I think you need to provide more details. But I also think you can hard-code the default value inside "reference" custom component.
Hi,
Agree with Karl515-ZrIyBv on providing more details.
Supposing that reference component has a backend side, for example a sling model, you could decide if, the path property of the component is empty, use a default path instead.
Views
Replies
Total Likes
Hi,
value should work only if the component is not edited. You might have edited component before and trying with value property. It is not gonna work.
you can try with cq:template property as well, which add the default property as soon as prelogin node created in content.
AEM Developer Learning : cq:template and cq:templatePath Properties of a Component in AEM
But try with new page or delete the prelogin node from content first then try with value and cq:template
Views
Replies
Total Likes
Hi All,
Please check my requirement:
I am using the reference component directly in my header.html, so that whenever author will create a page by using my pre-login-text template( this is static template not editable), it will auto populate with the default value, so author will not going to add any reference path in the edit mode of the page.
header.html:( my static template pointing to header.html file)
<div class="contain">
<sly data-sly-resource="${'prelogin' @ resourceType='/apps/project/components/global/reference'}"></sly>
</div>
and below is my reference component:
but whenever I am creating new page , it always showing empty path field. I have tried with "value" property also.
because I am using static template here then I have tried to add value on template level and its working fine, now can I do like this(adding value on template level) , is it correct in AEM6.4. Please suggest.
Regards,
Views
Replies
Total Likes
Hi,
yes, you can do that but for the existing page, you can see 500 error.
you can put a check though to avoid that.
and you can add prelogin in page component's htl code like
<sly data-sly-resource="prelogin"></sly>
Views
Replies
Total Likes
HI Arun,
yes, you are correct its working only for new pages for existing pages its not able to find out the node, getting 500 error.
How can I add check here, do I need to add at page component level?
Regards,
Views
Replies
Total Likes
you need to check if prelogin resource exists on not using java or server-side JS Use API.
Example : JS use API
Create a prelogin.js file wherever your HTL code file(header.html) is there and update below code in files
prelogin.js
use(function () {
var res = resource.getChild("prelogin");
var exists=true;
if(res==null){
exists=false;
}
return {
exists:exists
};
});
header.html - HTL snippet
<sly data-sly-use.prelogin="prelogin.js" data-sly-test="${prelogin.exists==true}" data-sly-resource="prelogin"></sly>
Views
Replies
Total Likes
Hi Arun,
thanks again and check is working fine but how can I add "prelogin" reference node/component in existing pages, is their any way to inject "prelogin" in existing pages without authoring.
Views
Replies
Total Likes
Hi,
You can write a servlet which query site to looks for pages which doesn't have prelogin and add prelogin node with default property using java API
SQL2 Query could be like below:
SELECT * FROM [cq:Page] AS s where isdescendantnode([/content/mfHTL63]) and s.[jcr:content/sling:resourceType] like '%mfHTL63/components/structure/page%' and s.[jcr:content/prelogin/sling:resourceType] not like '%mfHTL63/components/content/reference%'
Servlet Example
aem63app-repo/SimpleSQL2SearchServlet.java at master · arunpatidar02/aem63app-repo · GitHub
Node API example
final NodeIterator result = query.execute().getNodes();
while(result.hasNext()){
Node node=result.nextNode().getChild("jcr:content").addNode("prelogin", "nt:unstructured");
node.setProperty("reference", "/content/mfHTL63/en/jcr:content/header");
}
Thanks Arun .
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies