HrefLang Tag addition

aravindS

29-07-2019

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,

Accepted Solutions (1)

Accepted Solutions (1)

Arun_Patidar

MVP

20-08-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>

Answers (6)

Answers (6)

aravindS

19-08-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>

AnkurAhlawat

19-08-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>

Arun_Patidar

MVP

19-08-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>