Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

HrefLang Tag addition

Avatar

Level 4

Hi,

I need the add the link :

<link rel="alternate" href="http://example.com" hreflang="en-us" /> 

like this.

So, i added the property for href as 'hrefLangTag' and hreflang as 'region'

FYI,

<sly data-sly-list.href="${properties['hrefLangTag']}" data-sly-test.spec="${properties['region']}">

<link rel="alternate" href="${href}" hreflang="${spec}"></link>

</sly>

i used the code like above.. it was adding the <link> 16 times..

Help me to resolve this,

Example - 4 link we have. it gives the result 16 links

How to iterate only using href.

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

you can try like below:

To show single item from region based on herflang item.

<sly data-sly-list.href="${properties['hrefLangTag']}" data-sly-test.spec="${properties['region']}">

     <link rel="alternate" href="${href}" hreflang="${spec[hrefList.index]}"></link>

</sly>



Arun Patidar

View solution in original post

7 Replies

Avatar

Level 10

Can you confirm which Adobe product you are using?

Avatar

Level 4

Hi jantzen,

We are using AEM 6.3.3.4 .

Thanks,

Aravind

Avatar

Community Advisor

Can you explain little bit more, how data is saved in repo and what is the expected output. Why are you not using below:

<link rel="alternate" href="${properties['hrefLangTag']}" hreflang="${properties['region']}"></link>

or

<sly data-sly-test.spec="${properties['region']}">

<sly data-sly-test.href="${properties['hrefLangTag']}">

<sly data-sly-test.spec="${spec || href}">

<link rel="alternate" href="${href}" hreflang="${spec}"></link>

</sly>



Arun Patidar

Avatar

Level 7

Hello Aravind,

In your code snipet :-

<sly data-sly-list.href="${properties['hrefLangTag']}" data-sly-test.spec="${properties['region']}">

<link rel="alternate" href="${href}" hreflang="${spec}"></link>

</sly>

data-sly-list - This tag is used for iterating a list, so definitely it is going to print the content inside the block equal to size of the list <link rel="alternate" >.

data-sly-test - This tag is used for testing condition true or false means if ${properties['region']} is null or blank it is not going to print anything.

Now if you want to print it only single time putting condition like ${properties['region']} is not null. Then you can use below code snipet

<sly data-sly-test.spec="${properties['region']}">

<link rel="alternate" href="${properties['hrefLangTag']}" hreflang="${properties['region']}"></link>

</sly>

Avatar

Level 4

Hi Arun,

For my case, take an example

i have 10 values in the field with the name of (hrefLangTag) and one more property like (region).

I want to print like

<sly data-sly-list.href="${properties['hrefLangTag']}" data-sly-test.spec="${properties['region']}">

<link rel="alternate" href="${href}" hreflang="${spec}"></link>

</sly>

1st hrefLangTag to 1st region

2nd hrefLangTag to 2nd region

....like that.

The tag like--

<link rel="alternate" href="www.google.com/.." hreflang="en-us"></link>

<link rel="alternate" href="www.yahoo.com/.." hreflang="en-uk"></link>

<link rel="alternate" href="www.adobe.com/.." hreflang="en-eu"></link>

Avatar

Correct answer by
Community Advisor

you can try like below:

To show single item from region based on herflang item.

<sly data-sly-list.href="${properties['hrefLangTag']}" data-sly-test.spec="${properties['region']}">

     <link rel="alternate" href="${href}" hreflang="${spec[hrefList.index]}"></link>

</sly>



Arun Patidar