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.

    safer weather template by adding a remote config variable

    Scheduled Pinned Locked Moved Unsolved Feature Requests
    6 Posts 2 Posters 1.1k Views 2 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.
    • kayakbabeK Offline
      kayakbabe
      last edited by

      The compliments module is great. I love the remoteFile config variable so that I can add my own custom list of special date messages and other things. The beauty is that a custom file of compliments doesn’t get erased upon updating the mm and is easy to copy to another mirror instance. It is also easy to find to add or alter the compliments.

      The weather module uses external template files like current.njk and forcast.njk. It is possible to modify them to make the weather appear as we like. But they are at risk of being overwritten by an update to the mirror.

      I think that having a weather module config variable for a custom template would make updating less stressful and easier.

      To that end I have modified my local weather module instance as follows.

      In the weather module weather.js defaults section I added

      	defaults: {
      		remoteTemplate: "current.njk",
      

      and I altered the getTemplate function to the following:

      	// Select the template depending on the display type.
      	getTemplate: function () {
      		
      		if (this.config.remoteTemplate !="") {return this.config.remoteTemplate}
      		 else {
      		
      			switch (this.config.type.toLowerCase()) {
      				case "current":
      					return "current.njk";
      				case "hourly":
      					return "hourly.njk";
      				case "daily":
      				case "forecast":
      					return "forecast.njk";
      				//Make the invalid values use the "Loading..." from forecast
      				default:
      					return "forecast.njk";
      			}
      	   }
      	},
      

      Thus, if I do not create or set a remote template, the module will not fail, it will get the template it should.
      But I want to use a custom template becuase I want control to the css tags used in the html so I can more easily customise the weather. I also wanted a different layout. So made copies of current.njk and forecast.njk and put them in the mm config folder. I also renamed them to be very clear they were my custom template.
      Then,
      in the weather section of my config.js
      I added the relative path to my custom template file.

      config: {
        remoteTemplate: "../../../../config/kellyforecast.njk",
      

      I actually have a custom version of current and forecast templates. I can quickly tweak the templates and not get into the folder structure of the mm default modules.

      I would like to contribute this to the mm repository.

      S 2 Replies Last reply Reply Quote 0
      • S Away
        sdetweil @kayakbabe
        last edited by

        @kayakbabe submit a PR on github

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • S Away
          sdetweil @kayakbabe
          last edited by

          @kayakbabe compliments also is primarily configured thru the config.js, which will not be impacted by mm updates

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          kayakbabeK 1 Reply Last reply Reply Quote 0
          • kayakbabeK Offline
            kayakbabe @sdetweil
            last edited by

            @sdetweil true, and it also allows for a remote file, an extra config file if you will. I think the weather should do the same for it’s templates.

            S 1 Reply Last reply Reply Quote 0
            • S Away
              sdetweil @kayakbabe
              last edited by

              @kayakbabe I understand. I was just describing what appeared to be a misunderstanding of how compliments is configured.

              all the settings are in config.js, while A file can contain the text choices…

              I understand your reason for changing the template, altho I find the dsl for njk completely obtuse, and wouldn’t wish that on anyone.

              we have enough troubles w supporting just the settings
              without opening the layout to user construction

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              kayakbabeK 1 Reply Last reply Reply Quote 0
              • kayakbabeK Offline
                kayakbabe @sdetweil
                last edited by

                @sdetweil I totally get the difficulty in supporting people. I have been picking njk apart by examples already in the njk templates that I’ve found.

                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