简体   繁体   中英

tal nested dictionary syntax

Working with Pyramid, my code looks like this:

class PageData:
    @staticmethod
    def create_data():
        return [
            {   
                'key_1A': 'info1A',
                'key_2A': 'info2A',
                'nested_list_A': [
                    {'nested_key1A': 'nested_val1A'},
                    {'nested_key2A': 'nested_val2A'},
                ],
            },
            {   
                'key_1A': 'info1B',
                'key_2A': 'info2B',
                'nested_list_B': [
                    {'nested_key1B': 'nested_val1B'},
                    {'nested_key2A': 'nested_val2A'},
                ],
            },
            ]

And my html page code looks like this:

<span tal:condition="nested_key1A">     Open     </span>
<span tal:condition="not nested_key1A"> Closed   </span>

What is the proper syntax to reference nested_key? for a tal:condition statement?

In trying to figure this out I found my answer...

tal:repeat Syntax: tal:repeat="name expression"

Description: Evaluates "expression", and if it is a sequence, repeats this tag and all children once for each item in the sequence. The "name" will be set to the value of the item in the current iteration, and is also the name of the repeat variable . The repeat variable is accessible using the TAL path: repeat/name and has the following properties:

https://www.owlfish.com/software/simpleTAL/tal-guide.html

<div tal:repeat="a nest_list_A">
<div tal:repeat="b a.nest_list_A">
<span tal:condition="b.nested_key1A">

a becomes the assignment for nest_list_A eg b becomes the assignment for a.nested_list_A which will then access they key

if there is a value for the key, then tal:condition will continue as normal, otherwise it will skip while rendering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM