Is there a way to set a page level variable which can be used across components (By Content Authors or System Developers) in the page?
e.g. I have a query string parameter in the page URL (www.mysite.com/start.html?product=chair). I want to set the value 'chair' in some page level variable so that when content authors write the content they can use this variable in any component on the page using something like PAGE_VARIABLE[product]. Same variable can be used in system developers in their code as well.
Is there a way to solve this problem in AEM 6.2?
TIA
Solved! Go to Solution.
AEM does not support Global variable across pages. That is - you cannot declare a global variable in 1 location and use that through the site. Each page has its own variables that you can populate with a component dialog for example.
Lets assume each page has a variable named Foo. This is not a single variable but different variables with same name.
You could in theory could populate the Foo variable on each page by using an OSGi configuration setting whose value would be used to populate the Foo variables throughout a site. Then each page can call a service/AJAX operation that would read that OSGi configuration value and return the value so it would populate the Foo variables used in different pages.
Another thing that AEM supports with respect to sharing common information across multiple pages is Content Fragments. See this community article.
https://helpx.adobe.com/experience-manager/using/content-fragments.html
You can use Content Fragments to display common information throughout a site.
Views
Replies
Total Likes
Hi
Option 1:
Download "ACS AEM Commons" and use it as a global variable. The generic Lists are a feature allowing easy creation and management of lists of title/value pairs.
Link:- https://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists.html
Option 2:
If your aim is to save a value to a variable that could be used across the pages, then you can also save that value into a JCR node and can re-use it as per your need by fetching it value.
I hope this would help you.
~kautuk
Views
Replies
Total Likes
Thanks for the input but My question was using the variable 'Foo' across components in the same page and it should allow authors to inject Foo' variable wherever they want to do in their content.
Using ACS approach doesn't give the flexibility to enter this variable as part of content.
Using Content Fragments is also not a viable solution here as it would mean I will have to inject fragment component multiple times in a single page just to replace one variable.
There are other legacy CMS systems which solve this basic problem very easily and I am surprised that there is nothing in parallel available in AEM.
Views
Replies
Total Likes
AEM solve Content Fragments - larger chunks of data as opposed a single variable. It would be easy to populate Foo by hooking into a service that would would return a constant value. You can set a JCR node with a constant value and each instance of Foo could read this value. Hence you have variables throughout the site with the same value.
Views
Replies
Total Likes
As stated by Scott, If you want to save value by sending it as a query parameters, then you can create a custom service to accept it and then using JCR Api you can add/fetch it from JCR.
~kautuk
Views
Replies
Total Likes
Have you tried using design components? Site level values can be stored there, and editors / authors can update those values via the Design context. You can specify a template's designPath as the Global path (eg. home page template), and any design level updates to that design path can be used across any template by accessing the value via code.
Views
Replies
Total Likes
Add your property (foo) to your site's base page/home page properties under which authors create site content. Then get that property value wherever you need (like other components) using the below code -
InheritanceValueMap basePageProperties = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
String foo = basePageProperties.getInherited("foo", String.class);
Here you need to pass the current page's resource. Make sure that your global property name should be unique. It will get the value of first matched property from the current page to higher level pages.
or in HTL/Sightly:
${inheritedPageProperties.foo}
Hi Visser
We what to use some think like a substitution parameter or global variable. where the author can enter the value in the dialog.. for example in the text box/rte author might enter {gob_variable} and it should be replaced by company name. every site the company name is different and we would like to use the live copies to create all our sister companies ...
any thoughts are highly appreciated
thanks
Tharun
Views
Replies
Total Likes
Views
Likes
Replies