Loops and nesting in PPTX templates

You can learn how to create bullet lists and tables in other sections of this documentation. Here we will learn how to implement more complex scenarios with nesting.

The templating engine allows you to create following repeating objects:

  • tables,

  • bullet lists,

  • slides.

You can create nested constructions by putting one repeating object inside another.

First of all, review the loops and nesting demo. We will take a source object from that demo. As it is very large, we put it at the end of this article. It is a complex object with a few nested objects and collections:

Here we have a collection of employees. Each employee has a collection of companies where they worked. For each company, they have a collection of projects. Each project has a collection of achievements.

Now let us take a look at the source template for this structure:

Loops and nesting template

You can refer a property inside collection in your template. You can even refer a property inside a collection nested in another collection.

Examples:

  • tag {{name}} renders a list of employee names,

  • tag {{companies.name}} renders a list of company names,

  • tag {{companies.projects.name}} renders bullet list of project names on the slides of the accordant companies.

Actually, all tags in the template above refer properties inside collections. The templating engine understands it and iterates through all objects in those nested collections to render them. It is smart enough to understand what content needs to be duplicated.

When the engine finds a tag that refers to a collection, it tries to find the nearest object that can be duplicated. For example:

  • table cell,

  • bullet list item,

  • slide.

If nothing found, it thinks that whole presentation needs to be duplicated.

You can see the result of rendering below. There are all possible types of repeating objects nested one inside another:

Loops and nesting result

[
    {
        "name": "David Navarro",
        "companies": [
            {
                "name": "Plumsail",
                "projects": [
                    {
                        "name": "Plumsail Actions",
                        "achievement": [
                            {
                                "description": "Design the hardware"
                            },
                            {
                                "description": "Design the software"
                            },
                            {
                                "description": "Implement the software"
                            }
                        ]
                    },
                    {
                        "name": "Plumsail Forms",
                        "achievement": [
                            {
                                "description": "Design everything"
                            },
                            {
                                "description": "Implement everything"
                            }
                        ]
                    }
                ],
                "managers": [
                    {
                        "name": "Derek Clark",
                        "title": "Head of Development",
                        "reference": "he likes programming \nand good coffee"
                    },
                    {
                        "name": "Jessica Adams",
                        "title": "CEO",
                        "reference": "I don't know this guy"
                    }
                ]
            },
            {
                "name": "Contoso",
                "projects": [
                    {
                        "name": "Who knows what it was",
                        "achievement": [
                            {
                                "description": "R&D"
                            },
                            {
                                "description": "Bureaucracy"
                            }
                        ]
                    }
                ],
                "managers": [
                    {
                        "name": "Lots of people",
                        "title": "Managers",
                        "reference": "I saw this guy once in the cafeteria"
                    }
                ]
            }
        ]
    },
    {
        "name": "Martin Harris",
        "companies": [
            {
                "name": "Plumsail",
                "projects": [
                    {
                        "name": "Plumsail Org Chart",
                        "achievement": [
                            {
                                "description": "Mentor"
                            },
                            {
                                "description": "Teach"
                            }
                        ]
                    }
                ],
                "managers": [
                    {
                        "name": "Anil Mittal",
                        "title": "Founder",
                        "reference": "I like the way he laughs"
                    }
                ]
            },
            {
                "name": "Contoso",
                "projects": [
                    {
                        "name": "Whatever it was",
                        "achievement": [
                            {
                                "description": "R&D"
                            },
                            {
                                "description": "Documentation"
                            }
                        ]
                    },
                    {
                        "name": "Another old project",
                        "achievement": [
                            {
                                "description": "Research"
                            },
                            {
                                "description": "Development"
                            }
                        ]
                    }
                ],
                "managers": [
                    {
                        "name": "Brenda Coel",
                        "title": "Head of Heads",
                        "reference": "he knows the stuff"
                    },
                    {
                        "name": "Xue Li",
                        "title": "CEO",
                        "reference": "Brenda said he knows the stuff"
                    }
                ]
            }
        ]
    }
]