Rafamear wrote: ↑November 5th, 2022, 9:47 pm
I was using the eclectic-tech tutorial to test some things and wanted to know how do I make [MeterConditionIcon] return an image when I can't get a value for the image, like for example when it's offline
This can be done fairly easily. To do it, you need to create a measure to "override" the built-in template measure. If it was not clear in electic-tech's tutorial, you should never alter the template include files. These need to stay in untouched condition so they can easily be swapped out in case of a change to the weather.com API.
The template measure that grabs the icon is
[@CurrentIcon]. Normally this is a number, but as you noticed it can be blank. Important to note, it will also be blank while the data is initially being fetched from the website. I mention this because after making this change, you may notice your "no value found" image appearing unless you take some precautions to prevent this (which I will show you).
So, first you create a measure to "wrap" the template measure. This measure goes in YOUR skin, not the template include file, and should appear after the lines that "@Include" the template files.
Code: Select all
[MeasureCurrentIcon]
Measure=String
String=@CurrentIcon
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
Disabled=1
Some things to notice:
First, notice that the measure is disabled. This is done to prevent your "no value found" image from appearing briefly when the skin first loads, and before any data is retrieved. After the data is fetched from the website, the master template include WebParser measure will fire off a !Bang that will enable all measures in the "Parents" group. The line
Group=Parents will allow the template WebParser measure to enable your custom measure here.
Second, what this measure does is do a string replace and change a blank icon value with the string "na" (short for "not applicable"). So all you need to do at this point is create your "no value found" weather icon and give it the name "na.png". Many icon packs you may find already have this icon defined.
Finally, you alter your existing
MeterConditionIcon like so:
Code: Select all
[MeterConditionIcon]
...
MeasureName=MeasureCurrentIcon
...