Headcontribution issue on freemarker template

Hello,

I want to add meta properties in my html with headcontrbution using freemarker template.

I have added below code at test.ftl
<#assign hst=JspTaglibs[“http://www.hippoecm.org/jsp/hst/core”] >
<@hst.defineObjects />

 <@hst.headContribution keyHint="demo"> 
	<meta property="og:title" content="Title of Document"/>
	<meta property="og:type" content="article" /> 
	<meta property="og:url" content="PageURL"/>
	<meta property="og:image" content="PictureURL"/> 
 </@hst.headContribution> 

And at my root template:

       <#assign hst=JspTaglibs["http://www.hippoecm.org/jsp/hst/core"] >
       <@hst.defineObjects />

<@hst.headContributions categoryIncludes="htmlHead" keyHint="demo"/> 

This is not working for me. Even if I tried to add empty head contribution tag with dummy values, it does not render.
Can you please suggest something for this?

Thanks and Regards,
Bharat

Hello Bharat,

First as you define a category in your headContributions i would add this category to your headContribution so <@hst.headContribution keyHint=“demo” category=“htmlHead”>.

And second it was mentioned in a recent post [1] that headContribution accepts a single element. So wrap each meta tag you want to contribute in <@hst.headContribution tags

Hope this helps and kind regards.

Lef

[1] https://community.bloomreach.com/t/multiple-elements-inside-headcontribution-throwing-error/528

It seems you are missing property category in tag <hst.headContribution>
So you should have <@hst.headContribution keyHint=“demo” category=“htmlHead”>

Hi Bharat,

it seems to me that the category attribute [1] is missing in the head contribution.

HTH,
Giacomo

[1] https://www.onehippo.org/library/concepts/web-application/head-contributions.html

Thanks for your quick reply guys. But I had tried with setting the category attribute and also setting the each meta property in individual head contribution. This not helped me.

Regards,
Bharat

Hi Lef, thanks for your reply. I had earlier tried with these, but these are not helpful for me.

This should work:

<@hst.headContribution category=“htmlHead”>
<meta property=“og:title” content=“Title of Document”/>
</@hst.headContribution>

<@hst.headContributions categoryIncludes=“htmlHead" xhtml=“true”/>

technically you don’t need xhtml=true, but it probably can’t hurt.

However, you should have access to your document in your root component. Either set the content document on the request in your base component or you should be able to do

<meta property=“og:title” content="{ hstRequest.requestContext.contentBean.title}"/>

on your ftl. (syntax may not be perfect)

Thanks for the reply Jasper.
I will be able to access the dynamic things from my content. As I have included the tag library in the both FTLs and particular dependancies at pom.xml, this should work.
But the problem I am having is that freemarker template engine is not executing the head contribution tag.
For example, I am trying with dummy values as below, this is also not working.
At test.ftl
<@hst.headContribution keyHint=“demo” category=“htmlHead”> abcd </@hst.headContribution >

At root.ftl
<@hst.headContributions categoryIncludes=“htmlHead” keyHint=“demo”/>

Thanks and Regards
Bharat

keyHint is not valid on hst.headContributions

Thanks Jasper, this resolved my execution issue . I was trying to use key hint to avoid the collisions.