Read the statement by Michael Teeuw here.
Way to insert a HTML link in var
-
Hi everybody and first of all, sorry for my poor words choice, i’m not english native.
On my MM I Show pictures from a HTML link in Compliments module. In order to make my code prettier, i’m looking for a way to replace the HTML link by a var as I show the same picture in several modules compliments. My issue is that i don’t find the right syntax to make this work…
In other words, i want to replace
{
Module compliment 1 :
Image = https : //www…Module compliment 2 :
Image = https : //www…}
by
{
Img = https://Module compliment 1 :
ImgModule compliment 2 :
Img}
Thanks a lot if you’re smart enough to help me finding an answer !
-
@Tom_LabHIdouille there is no way to do it currently with the existing code.
its easy to create variables
module: "compliments", config: { some_var:"http:......." compliments:{..... } }
the problem is using them … thru config…
but a couple lines of code in getDom() could make this functional
compliements:{ anytime: [ "whatever", "var:some_var"]
and in getDom
// existing code (small change const to let) let complimentText. = this.randomC ompliment(); // new code if(complimentText.startsWith("var:") complimentText= this.config[complimentText.split(':')[1]]
now you would have to do more if the content is html (img src=“var:…”)
// loop thru the html content let lastindex=0 while(true){ let index = complimentText.indexOf('"var:',lastindex) if (index>=0){ lastindex=index // some code to extract the var: string and it variable //using indexOf and slice (note the previous found the " in front of var: // get its variable value from config // replace the string, and continue from the previous index (lastindex) } else break; // out of while loop }
-
@Tom_LabHIdouille you won’t be able to share the variable across module instances
-
@Tom_LabHIdouille I’m not familiar with compliments, but can’t you create a locale html-file at the modules folder with the link to the picture you prefer and add the name of the html at all the compliments-module(s).
The benefit would be only to change the locale file and all the compliments-modules should show your picture.