Hi Arun Patidar,
I thought about that solution. But I don't know how to pass image_src path to the ImageModel model.
Example: Singhtly HTML
<div class="title-and-booking show-on-web" data-sly-use.propertyObject="com.example.testimage.core.models.PropertiesById">
<div data-sly-use.imageObject="${'com.example.testimage.core.models.ImageModel' @ imagePath = 'propertyObject.property.image'}">
<img itemprop="image" id="img-top-most" src="${propertyObject.property.image}" alt="${imageObject.image.alt_text}">
</div>
</div>
The image model:
package com.example.testimage.core.models;
import com.adobe.cq.sightly.WCMUsePojo;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
public class ImageModel extends WCMUsePojo {
private String altTagImage;
private String urlImage;
private static final String DEFAULT_RESULT_EN = "Alt default value EN";
private static final String DEFAULT_RESULT_ZH = "Alt default value ZH";
private static final String LANG_CODE_ZH = "zh";
@Override
public void activate() throws Exception {
String langCode = getCurrentPage().getLanguage(true).getLanguage();
ResourceResolver resourceResolver = getResourceResolver();
String urlImage = getUrlImage();
if (StringUtils.isNotBlank(urlImage)) {
Resource resource = resourceResolver.getResource(urlImage + "/jcr:content/metadata");
if (resource != null) {
altTagImage = resource.getValueMap().get(langCode + "_alt_text", String.class);
}
}
if (StringUtils.isBlank(altTagImage)) {
altTagImage = DEFAULT_RESULT_EN;
if (LANG_CODE_ZH.equalsIgnoreCase(langCode)) {
altTagImage = DEFAULT_RESULT_ZH;
}
}
}
public String getAltTagImage() {
return altTagImage;
}
public String getUrlImage() {
return get("urlImage", String.class);
}
}
Please help me,
Thank you so much,