function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bill MurphyBill Murphy 

Design pattern to share a variable across all community pages

Hello everyone

I have a community with different pages. The community might be used in different countries so it will have some functionalities that are available in some cases but not in others (for example open current discounts).

I have a custom metadata type with records for each country where the settings for different functionalities are stored - for example 

UK - open current discounts - true
US - open current discounts - false.

Is there a way to get that information only once (I call an apex class that makes a query for the metadata) and set it for the session, so that all pages can use it or I have to call the method from each page.

 

 

MichelCRMichelCR
Hi Bill,

You could use a Single Page Application pattern. This link might help you to start: https://www.geeksforgeeks.org/what-is-spa-single-page-application-in-angularjs/
Bill MurphyBill Murphy

Hi Michael,

Thanks for the reply, but I do not want to integrate a third party app builder like Angular or React. From what I understand every page in the community builder is separate. You set header, content and footer components, but I do not see a general state store like Redux in React for example to link different pages.

MichelCRMichelCR
Hi Bill,

I understand. I don't this is possible because the way that natively SF provides is apex:composition (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_composition.htm), and this could help to reuse some HTML but not server calls. 
Maybe considering going with LWC in VF could help, take a look at this if it helps: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_composition.htm

I hope this helps