Spesific Child Pages & dynamic cannonical | Community
Skip to main content
Level 2
May 31, 2020
Solved

Spesific Child Pages & dynamic cannonical

  • May 31, 2020
  • 4 replies
  • 5364 views

Hello im trying to implements 2 things:

1. im trying to implement lang on particular page, every children pages will get this lang into 'efg' but the parent get lang="en"

what i did: lang="<${currentPage.path == '/content/path1/path2/parent(/.*)?'>" (not worked)

so i put manually every path of this children one by one, like "<${currentPage.path == '/content/path1/path2/parent/child1' || '/content/path1/path2/parent/child2"... ? 'efg' : 'en'

is there any method that can fix it? so i only need to call it once?

 

2. im trying tomake cannonical URL base on dynamic url

for example: <link rel="cannonical" href="${currentPage.path}"> and the outputs return "/content/path1/path2/parent"

how to get real url like "www.example.com/path1/path2/parent/file.html"

 

Thanks in advance

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 ArpitVarshney

Hi @iwanttobedev 

 

1. To solve your first issue, you can try below HTL generic code, which will be true for its all first-level children.

${currentPage.parent.path == '/content/path1/path2/parent'}

 

2. Go through this link https://stackoverflow.com/questions/19571249/get-current-page-url-in-adobe-cq5-for-canonical-link

 

Regards,

Arpit

4 replies

ArpitVarshney
Community Advisor
ArpitVarshneyCommunity AdvisorAccepted solution
Community Advisor
May 31, 2020

Hi @iwanttobedev 

 

1. To solve your first issue, you can try below HTL generic code, which will be true for its all first-level children.

${currentPage.parent.path == '/content/path1/path2/parent'}

 

2. Go through this link https://stackoverflow.com/questions/19571249/get-current-page-url-in-adobe-cq5-for-canonical-link

 

Regards,

Arpit

Level 2
May 31, 2020

bro that was great help, it solve the problem number 1, thanks

but about the post you mentioned above it said if it working on JSP, how about if im only using with simple HTML 5 where i put directy <link cannonical href="clues">, because is forbiden for me to changed the structure @arpitvarshney 

Shashi_Mulugu
Community Advisor
Community Advisor
June 1, 2020

For both of the things to work, please write a sling model based on Page and init() post construct method, put the logic of getting the current page and get the language properties and set the calculated language attribute into a gettermethod, please follow the same for second scenario as well.

 

In you sightly, you should simply write.

<sly data-sly-use.pagemodel="yourpackage.core.models.PageModel"/>
${pagemodel.language}
${pagemodel.canonical}

 

PS:- Please refrain from writing any backend logic in Sightly

Level 2
June 2, 2020

Actually i found a little tricky for this canonnical,for example:

<link rel="cannonical" href="https://www.example.co.id{$data.path}">

and on js i put:
data.pathh = currentPage.path.substr(13);
it will eliminate : '/content/test'

so it will return 'https://www.example.co.id/yourdinamycal/path.html"

thanks for any of your help.

Regards

ArpitVarshney
Community Advisor
Community Advisor
June 2, 2020

Hi @iwanttobedev 

 

This is not a good way to achieve this requirement. This is not a generic solution.

You should try @shashi_mulugu approach for this.

 

regards,

Arpit

Shashi_Mulugu
Community Advisor
Community Advisor
June 2, 2020

I think it is bad idea to use to string manipulation to do the URL shortening as AEM is a enterprise level CMS and you can never restrict the URL length. Please use the either/combination of options mentioned in below post along with externalizer to get the absolute paths. The same logic will also help you in shortening url in page content using link rewrites in future. I would love to use Sling Resolution along with Server level redirects to best use of the implementations.

 

https://shinesolutions.com/2017/01/04/demystifying-shortened-and-extension-less-urls-in-aem/