Server Side Handlebars Helper Disappears When Used in SCF Component
Hello, I have a server side handlebars helper that I'm trying to use inside of SCF components (Post, Topic, List-Item). It is working fine, but after the information shows up on the page, it disappears after a second.
Because our user profile nodes contain sensitive information in the properties, I cannot make them public as has been done for the geometrixx profiles. This is why I need to use a helper to get the username instead of using the oob {{author.name}}.
Here is the helper:
@Service @Component public class Username implements TemplateHelper<String>{ private final Logger LOGGER = LoggerFactory.getLogger(Username.class); @Reference private ResourceResolverFactory resourceResolverFactory; private static ResourceResolver resourceResolver; @Override public CharSequence apply(String context, Options options) throws IOException { try { if(resourceResolver == null) { resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null); } Resource resource = resourceResolver.getResource(context); ValueMap vals = resource.getValueMap(); String userId = vals.get("userIdentifier").toString(); return userId; } catch (Exception e) { LOGGER.error("Error getting id from context - " + e); return "Default User"; } } @Override public String getHelperName() { return "username"; } @Override public Class<String> getContextType() { return String.class; } }And then I use it like this in the components:
<p class="component-answerthread__profile-user">{{username this.id}}</p>(This is done inside of the component's tag where data-component-id="{{id}}" is declared just to be clear.)
Like I said, this is working. It shows up for a second and then disappears. Oddly, it works flawlessly when the user is not logged in (it doesn't disappear).