CheetahGenerator - Using multiple tags in one statement?

36 views
Skip to first unread message

Jared

unread,
Nov 22, 2020, 11:23:02 AM11/22/20
to weewx-user

Hi,

I'm trying to create a table of celestial objects with almanac data.  I want to use a for loop to create the table based on an array of chosen objects, but it doesn't like how I'm using the tags for some reason.

As an example, I have the following in my template:

#set planets = ['Mercury', 'Venus', 'Mars']

#for planet in planets
  <tr>
    <td class="celestialTableObject">$planet</td>
    <td class="celestialTableData">$almanac.$planet.rise</td>
    <td class="celestialTableData">$almanac.$planet.transit</td>
    <td class="celestialTableData">$almanac.$planet.set</td>
    <td class="celestialTableData">$almanac.$planet.az</td>
    <td class="celestialTableData">$almanac.$planet.alt</td>
    <td class="celestialTableData">$almanac.$planet.ra</td>
    <td class="celestialTableData">$almanac.$planet.dec</td>
    <td class="celestialTableData">$almanac.$planet.mag</td>
  </tr>
#end for


The table prints the planet name as expected, but all the data cells are printing with .$planet.rise .$planet.set and so on.

How can I get the CheetahGenerator to use both tags?

Jared

unread,
Nov 22, 2020, 11:35:16 AM11/22/20
to weewx-user
I should add that the almanac setup is working fine otherwise.  If I do something like $almanac.jupiter.rise, I get the data as expected.  I just wanted to keep my post concise :)

Tom Keffer

unread,
Nov 22, 2020, 11:47:52 AM11/22/20
to weewx-user
You're very close. The problem is that an expression like $almanac.$planet.rise is evaluated when the template is compiled not run. So, you need to defer evaluation of the attribute $planet. Try this (NOT TESTED):

#set planets = ['Mercury', 'Venus', 'Mars']

#for planet in planets
<tr>
<td class="celestialTableObject">$planet</td>
    <td class="celestialTableData">$getattr($almanac, $planet).rise</td>
<td class="celestialTableData">$getattr($almanac, $planet).transit</td>
<td class="celestialTableData">$getattr($almanac, $planet).set</td>
<td class="celestialTableData">$getattr($almanac, $planet).az</td>
<td class="celestialTableData">$getattr($almanac, $planet).alt</td>
<td class="celestialTableData">$getattr($almanac, $planet).ra</td>
<td class="celestialTableData">$getattr($almanac, $planet).dec</td>
<td class="celestialTableData">$getattr($almanac, $planet).mag</td>
</tr>
#end for


--
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/103a4b70-a4a2-4415-b966-e0d106a1ffd3n%40googlegroups.com.

Jared

unread,
Nov 22, 2020, 12:03:06 PM11/22/20
to weewx-user
Beautiful, that worked perfectly, thanks Tom!
Reply all
Reply to author
Forward
0 new messages