Expand my Community achievements bar.

SOLVED

Spesific Child Pages & dynamic cannonical

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 2

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 

Avatar

Community Advisor

Hi @iwanttobeDev 

 

You can construct your URL in the sling model class or WCMUse class(based on your project) and then call it to your HTL.

 

Regards,

Arpit

Avatar

Community Advisor

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

Avatar

Level 2

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

Avatar

Community Advisor

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

Avatar

Community Advisor

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/