On each page of my website I need to load the same data from a database. My website is composed of a header page which is common to all pages.
Is there a possibility to load the database only once and access the retrieved value from any page of the site?
It’s not possible to have a global constant string or so?
If i have a const in a page (const string test = “test”) then i is the same amount of code (or even more) to call for that const.
Like - if i store the string test in the session data - then i still have to write session.get(“test”) to get that test string. There’s no code saved and in the end it’s actually more code because i have to declare a variable and also get the data via a identifier…
We need something like a global variable - like you define it in the site as global const string test = “jfjfjaofijaofj”; and then use it on all pages with just calling the test variable…
In that case, Cloudy, you may consider to create a public js file (let’s name it vars.js) with the definition of a globalVars object containing all the constants you need in your site, by using an expression like this:
export let globalVars = {
test : “jfjfjaofijaofj”,
test2 : “what does ‘jfjfjaofijaofj’ mean BTW”
};
Then in each webpage you can simply import that object by using this line:
import {globalVars} from ‘public/vars.js’;
// → And directly access the object internal properties like this:
Console.log(globalVars.test); //which should output: jfjfjaofijaofj
Hi, I like your solution.
In the Export let globalVars you define varfiables that are statics. How can I define a variable that changes according to some criterias stored on the Collection for a specific logged in user?
@cliffhegan This thread is over two years old, so please create a new post with all the necessary details so you can get support. Refer to our guidelines to see what you should include in your post. Thanks.