Skip to content

safer weather template by adding a remote config variable #2880

Closed

Description

@Kayakbabe

_I posted this same topic on the forum. But putting it here as I think this might be a helpful feature to add to the default weather module.

Changing the code for the module to allow for a remote template file will not break the weather module if there is no config variable or no remote file. If not remote template is setup then the module will just work as before.

Forum link: https://forum.magicmirror.builders/topic/16957/safer-weather-template-by-adding-a-remote-config-variable?_=1657147849733
_

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.

Activity

  1. sdetweil commented on Oct 5, 2022

    @sdetweil
    Collaborator

    we should close one of these as a dup

  2. rejas commented on Oct 5, 2022

    @rejas
    Collaborator

    agreed. maybe one day @MichMich will give us issue-handling-rights ;-) (not sure if github allows such fine grained access rights though)

  3. MichMich commented on Oct 6, 2022

    @MichMich
    Collaborator

    I invited you three als collaborators. :) Without you three MagicMirror² wouldn't be what it is now. <3

  4. rejas commented on Oct 6, 2022

    @rejas
    Collaborator

    Awwww, thanks for the flowers (and the invite). Will try to not break your trust (and your code :-)

  5. khassel commented on Oct 6, 2022

    @khassel
    Collaborator

    Will try to not break your trust (and your code :-)

    me too ... currently I'm working with 2 git remotes on my machine, have from now on to double check not to push to the wrong repo ...

  6. rejas commented on Oct 6, 2022

    @rejas
    Collaborator

    I'll probably still be using my own fork for workinprogress. That way the main repo doesnt get trashed by my "late night ideas that never get finished"-branches :-) (plus I dont push in the wrong repo :-D

  7. khassel commented on Oct 6, 2022

    @khassel
    Collaborator

    meanwhile I configured a dummy-push-url for this repo ... ;)

  8. sdetweil commented on Oct 6, 2022

    @sdetweil
    Collaborator

    eh?

  9. khassel commented on Oct 6, 2022

    @khassel
    Collaborator

    o.k., more detailed ...

    you can work with more than one remote repository. E.g. I have 2 configured, my own fork of this repo and this repo.

    So I can work on the branches of my fork but can also fetch new stuff from the original repo.

    So far it was no problem if I tried to push accidentially to this repo because I got permission denied. Now we have these permissions ...

    Therefore I configured git in this way:

    $ git remote -v                                           
    k13     [email protected]:khassel/MagicMirror.git (fetch)    
    k13     [email protected]:khassel/MagicMirror.git (push)     
    origin  [email protected]:MichMich/MagicMirror.git (fetch)   
    origin  [email protected] (push)                            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions