MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Way to insert a HTML link in var

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    4 Posts 3 Posters 448 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Tom_LabHIdouilleT Offline
      Tom_LabHIdouille
      last edited by

      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 :
      Img

      Module compliment 2 :
      Img

      }

      Thanks a lot if you’re smart enough to help me finding an answer !

      S 2 Replies Last reply Reply Quote 0
      • S Offline
        sdetweil @Tom_LabHIdouille
        last edited by sdetweil

        @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
                           }
        

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @Tom_LabHIdouille
          last edited by

          @Tom_LabHIdouille you won’t be able to share the variable across module instances

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          thgmirrorT 1 Reply Last reply Reply Quote 0
          • thgmirrorT Offline
            thgmirror @sdetweil
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy