evaluation in templates

39 views
Skip to first unread message

Mic G77

unread,
Jul 7, 2019, 8:00:30 AM7/7/19
to weewx-user
Hello,
in the current.html.tmpl, i have written this code:
<td class="stats_data">$current.extraTemp6.raw-$current.extraHumid6.raw</td>

I was  expecting an evaluation of $current.extraTemp6.raw-$current.extraHumid6.raw
but i get (i suppose a string) : 13.7-70.0

How could the template evaluate the expression ?
I think it is possible because in the user_guide ( usr/share/doc/weewx/customizing.htm#Comprehensive_example), I've seen this line :

<td>$hour.start.format("%H:%M")-$hour.end.format("%H:%M")</td>


Thanks in advance,

Mic

gjr80

unread,
Jul 7, 2019, 8:13:35 AM7/7/19
to weewx-user
Hi,

What you saw in the template was not an evaluation (arithmetic) as such, but simply showing two times in hour:minute format separated by a hyphen, much like the result from your code. To do in-template arithmetic you need to have some in-line python code to do the arithmetic and assign the result to a variable then use the variable as a tag later in your template. Something like (untested):

#set $my_result = $current.extraTemp6.raw-$current.extraHumid6.raw
<td class="stats_data">$my_result</td>

The above is a very simplistic example (formatting will probably not be what you want) but it gives you a start. You will find in-line python in a number of the templates included with WeeWX.

Gary

Andrew Milner

unread,
Jul 7, 2019, 8:25:53 AM7/7/19
to weewx-user
seems a very strange thing to want to evaluate anyway - subtracting a humidity value from a temperature value!!

Thomas Keffer

unread,
Jul 7, 2019, 8:36:32 AM7/7/19
to weewx-user
You need to surround the expression with $(...) to get Cheetah to evaluate it, instead of just turn it into HTML. So, you want

$($current.extraTemp6.raw - $current.extraHumid6.raw)

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/d10751ed-ce27-465f-a19c-acffde9f3c8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gjr80

unread,
Jul 7, 2019, 8:37:53 AM7/7/19
to weewx-user
Well I didn’t know that, always thought though there must have been a more direct way, just never found it.

Gary
Reply all
Reply to author
Forward
0 new messages