Hi all,
I have created one custom tab under properties and given tagfield to let the author to select tags. Now I want to display those selected tags in the page. How can I do that ??
Solved! Go to Solution.
Views
Replies
Total Likes
You should use InheritanceValueMap to get page properties in Sling Model and Use Tag Manager to Resolve cq:tags.
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TagReadingFromPageProperties {
@Inject
private InheritanceValueMap pageProperties;
@Self
private SlingHttpServletRequest request;
Map<String, String> tagMap;
@PostConstruct
protected void init() {
String[] allTags = pageProperties.get("cq:tags", String[].class);
TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class);
tagMap = new HashMap<>();
for (String tags : allTags) {
Tag tag = tagManager.resolve(tags);
tagMap.put(tag.getName(), tag.getTitle());
}
}
public Map<String, String> getTagMap() {
return tagMap;
}
}
You can iterate tagMap to get list through sightly.
You should resolve a tag via TagManager (https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq...
resourceResolver.adaptTo(TagManager.class)
@Tessa_learner1 It should be straight forward:
@Model(adaptable=Resource.class) public class myClass { @Self Resource resource; List<String> tagNames; @PostConstruct public void init() { PageManager pm = resource.getResourceResolver().adaptTo(PageManager.class); Page containingPage = pm.getContainingPage (resource); ValueMap pageProperties = containingPage.getProperties(); String[] tags = pageProperties.get("cq:tags", new String[0]);
tagNames = new ArrayList<>(); TagManager tagManager = resourceResolver.adaptTo(TagManager.class); for(String tag : tags){ Tag tag = tagManager.resolve(tag);
tagNames.add(tag.getTitle); } } }
You can display the list using sightly in the component.
Thanks
Refer TagManager API https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq...
You should use InheritanceValueMap to get page properties in Sling Model and Use Tag Manager to Resolve cq:tags.
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TagReadingFromPageProperties {
@Inject
private InheritanceValueMap pageProperties;
@Self
private SlingHttpServletRequest request;
Map<String, String> tagMap;
@PostConstruct
protected void init() {
String[] allTags = pageProperties.get("cq:tags", String[].class);
TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class);
tagMap = new HashMap<>();
for (String tags : allTags) {
Tag tag = tagManager.resolve(tags);
tagMap.put(tag.getName(), tag.getTitle());
}
}
public Map<String, String> getTagMap() {
return tagMap;
}
}
You can iterate tagMap to get list through sightly.
Views
Likes
Replies