HrefLang Tag addition | Community
Skip to main content
Level 5
July 29, 2019
Solved

HrefLang Tag addition

  • July 29, 2019
  • 7 replies
  • 5983 views

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,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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>

7 replies

jantzen_b
Adobe Employee
Adobe Employee
August 8, 2019

Can you confirm which Adobe product you are using?

aravindSAuthor
Level 5
August 9, 2019

Hi jantzen,

We are using AEM 6.3.3.4 .

Thanks,

Aravind

jantzen_b
Adobe Employee
Adobe Employee
August 19, 2019

Perfect. I'll move this question to the Adobe Experience Manager​ community.

arunpatidar
Community Advisor
Community Advisor
August 19, 2019

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
AnkurAhlawat-1
Level 6
August 20, 2019

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>

aravindSAuthor
Level 5
August 20, 2019

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>

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
August 20, 2019

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