How to make a lot of pages using the same template without having to manually create the markdown file

Let’s say we make a website for a company with 100 offices and we need to make an address page for each office, how would you solve this problem? Are there examples of a solution, without creating a file and folder for each page, for example with JSON or XML where all the data for the pages template.

@Serebrennikov Interesting case…

The following is just one of the possibilities to create pages with dynamic content.

I am presuming you have an ‘office selector’ on some page where visitors can select an office and direct them to the contact page with the correct query parameter. This ‘office selector’ can be created dynamically based on the ‘offices.yaml’ content.

  • Create a page ‘/user/pages/’ containing:
    title: Contact
      twig: true   <-- This will switch on the processing of Twig in Markdown
    Our {{ uri.query('office') | capitalize }} office:
    <p>Address: {{ config.offices[uri.query('office')].address }}</p>
  • Create file ‘/user/config/offices.yaml’ containing:
      address: Piccadilly Circus
      address: Avenue des Champs-Élysées
  • Point your browser to ‘https://mydomain/contact?office=paris’ and see what happens…

Adding some testing for valid query strings and existing office names might be useful.

Hope this will give you an idea to start with…

1 Like