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.

Dynamically set locale in querybuilder

Avatar

Level 2

Hello there!
I'll try to make it fast and simple:
I created some queries to find specific content, every query has its own "path=/content/x". But from now the site will have two language, italian and english, so two different path for different content. Before the internationalization I've always set the path field hardcoding "/content/nameproject/en/us/" (if I was looking for pages) or "/content/dam/nameproject/"(for assets). I'm aiming to do something like this => if I visit the italian page every query should have this path "/content/nameproject/it/it-it/" and if I visit the english page this should be the path "/content/nameproject/en/us/"

 

4 Replies

Avatar

Community Advisor

Do you have any page properties which identifies the locale and language information, if not have some configurations on the root level and read them in your code using inherited page properties, then try to form the path dynamically, this should you path dynamic and query to be executed dynamically.

For more examples on inheritedpageproperties refer this.

https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-os...

Avatar

Community Advisor

If the project has more requirements for language-specific configurations, paths etc. it might be worth to explore context-aware configurations.

that way all configs related to italian site can stay in that content hierarchy. The common code could use this configs and return appropriate results

https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati... 


Aanchal Sikka

Avatar

Community Advisor

where is your query builder related logic written? is it at component level model or service or at the servlet level?

1. if the your custom code is written on sling model /service level, then you can get the current page path and split the path to identify the languagecode/locale then construct the root path dynamically. 

2. If you're writing your logic at servlet, then you can pass thelanguagecode/locale as parameters and construct the root path dynamically. 

Hope this helps.

Avatar

Employee Advisor

@lezzowski1 It depends how your query is being constructed. You can add query construct logic on page level, where in it can fetch current path as query path and so on.