Dear All,
I have one dialog , where I have defined skuid , installation label and installation link , as shown below.
Now , my requirement is that if Sku ID is blank ("null") then it will display the installation document link in sightly
if Sku ID is not blank ("not null") then it will display the Sku ID link in sightly.
For above , I have written below in the sightly. But it is not working fine , as shown below.
**************SIGHTLY CODE **********************
<div class="installation-documents" data-sly-use.installationdocuments="com.sunita.core.components.models.InstallationDocumentModel">
<h2 class="installation_header">${installationdocuments.header}</h2>
<div>${installationdocuments.description @CONTEXT = 'html'}</div>
<!-- <div><h3>${installationdocuments.skuid}</h3></div> -->
<sly data-sly-test="${installationdocuments.skuid == '' || installationdocuments.skuid == null}">
<h2> Sku-ID null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html${installationdocuments.installationLink}" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
<sly data-sly-test="${installationdocuments.skuid != '' || installationdocuments.skuid != null}">
<h2> Sku-ID not null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html/content/dam/referencesite/bathroomproducts/${installationdocuments.skuid}.pdf" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
</div>
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @dipu2
Try below:
<sly data-sly-test.skuid="${installationdocuments.skuid}">
<h2> Sku-ID not null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html/content/dam/referencesite/bathroomproducts/${installationdocuments.skuid}.pdf" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
<sly data-sly-test="${!skuid}">
<h2> Sku-ID null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html${installationdocuments.installationLink}" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
In above changes, I am checking sku id not null first and variable in expression in data-sly-test take both null as empty as false. So, there is no need to check empty and null seperately.
Hope it helps!
Thanks!
Nupur
Adding to above , in my sightly output both null and not null is coming , as shown above.
Views
Replies
Total Likes
Hi @dipu2
Try below:
<sly data-sly-test.skuid="${installationdocuments.skuid}">
<h2> Sku-ID not null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html/content/dam/referencesite/bathroomproducts/${installationdocuments.skuid}.pdf" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
<sly data-sly-test="${!skuid}">
<h2> Sku-ID null</h2>
<ul>
<a class="new-tab" href="http://localhost:4502/assetdetails.html${installationdocuments.installationLink}" target="_blank">
${installationdocuments.installationLabel}
</a>
</ul>
</sly>
In above changes, I am checking sku id not null first and variable in expression in data-sly-test take both null as empty as false. So, there is no need to check empty and null seperately.
Hope it helps!
Thanks!
Nupur
Adding on to @Nupur_Jain,
Can you please provide the Sling Model implementation. You might have written you Sling Model improperly.
HI Brian,
I do not think there is any issue in my slingmodel , as it is very much blank.
Below is my slingmodel.
protected static final Logger LOGGER = LoggerFactory.getLogger(InstallationDocumentImpl.class);
private Session session;
@reference
private QueryBuilder builder;
// Inject a Sling ResourceResolverFactory
@reference
private ResourceResolverFactory resolverFactory;
@ValueMapValue
@Via("resource")
private String header;
@ValueMapValue
@Via("resource")
private String description;
@ValueMapValue
@Via("resource")
private String skuid;
@ValueMapValue
@Via("resource")
private String installationLabel;
@ValueMapValue
@Via("resource")
private String installationLink;
@ScriptVariable
private Page currentPage;
// Inject the installationdocmtlink node under the current node
/*
* @inject
*
* @Deleted Account public Resource installationdocmtlink;
*/
public static String getResourceType() {
return RESOURCE_TYPE;
}
@Override
public String getExportedType() {
return RESOURCE_TYPE;
}
@Override
public String getHeader() {
// LOGGER.info("Before return header *******" + header);
return header;
}
@Override
public String getDescription() {
// LOGGER.info("Before return description *******" + description);
return description;
}
@Override
public String getSkuid() {
LOGGER.info("Before return skuid *******" + skuid);
return skuid;
}
@Override
public String getInstallationLabel() {
LOGGER.info("Before return installationLabel *******" + installationLabel);
return installationLabel;
}
@PostConstruct
private void initModel() throws Exception {
LOGGER.info("after return installationLink *******" + installationLink);
}
@Override
public String getInstallationLink() {
LOGGER.info("Before return installationLink *******" + installationLink);
return installationLink;
}
}
Views
Replies
Total Likes
Thanks Nupur .
It is working now.
I have one small question here.
Currently I have hard coded the href , as shown below
<a class="new-tab" href="http://localhost:4502/assetdetails.html/content/dam/referencesite/bathroomproducts/${installationdocuments.skuid}.pdf" target="_blank">
Is there any way to not hard coded ??http://localhost:4502/assetdetails.html/content/dam/referencesite/bathroomproducts and show the url
Also when I am trying to use below in my HTML by using the path link ,
<a class="new-tab" href="${installationdocuments.installationLink @CONTEXT = 'uri'}" target="_blank">
${installationdocuments.installationLabel}
My PDF file is downloading , but not opening as URL...in new tab.
My cq dialog is like above .
Views
Replies
Total Likes
My cq:dialog for pathlink is as below.
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies