Multiple elements inside Headcontribution throwing error

Hi Team,

I am facing few strange problems with @hst.headcontribution tag, I have checked the official documentation as well but no luck. Please help.

My Issue is if I am putting multiple items inside headcontribution its giving Error, However for single item its working perfectly fine. So take below example:

Example 1: Its working fine

    <@hst.headContribution category="htmlHead"> 
            <title>${document.title?html} - Dainikinsider </title>

Example 2: Its not working and throwing Error

     <@hst.headContribution category="htmlHead"> 
             <title>${document.title?html} - Dainikinsider </title>
                <meta content='${document.description?html}' name='description' ></meta>
         <meta content='${document.keywords?html}' name='keywords' ></meta>

        <meta content='${document.title?html}' property='og:title' ></meta>
        <meta content='blog details canonical URL' property='og:url' ></meta>
        <meta content='article' property='og:type' ></meta>

NOTE: I Tried with inline meta tag as well, but that was also not working

Also it it possible to have Javascript code inside head contribution, I tried but It was not working

Now Below are my Questions based on above problems:

  • If its not possible to place multiple items inside HeadContribution, then do we have any other way ?
  • if its possible then what;s wrong with above code ?

You can only have on element in a head contribution tag. Though that element itself could contain multiple elements, as long as the head contribution element has only one child tag.

You will need multiple head elements. What you could do for the meta tags is put them in a map, then loop over the map to create the different head contribution elements. Still need multiple head contribution tags, but it would be a bit cleaner in your template.

it is possible, you just need to escape it properly: it needs to be valid xml, so characters like & needs to be encoded like "& amp; " …easier is to just wrap it into CDATA block.