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
On Sun, Nov 22, 2020 at 8:35 AM Jared <[email protected]> wrote:
> 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 :)
>
> On Sunday, November 22, 2020 at 11:23:02 AM UTC-5 Jared wrote:
>
>>
>> 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?
>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/103a4b70-a4a2-4415-b966-e0d106a1ffd3n%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-user/103a4b70-a4a2-4415-b966-e0d106a1ffd3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/CAPq0zECNymvfar1nc6VsuwViL73%3DcFCjr2d4c8FqbAE39cS05Q%40mail.gmail.com.