Displaying a form within a modal

Hi,
I am totally new to grav.
I’m trying to display a form within a modal, so, something like this:

---
title: Portfolio
menu: portfolio
portfolios:
    - title: Home
<Insert form1 here>
      subtitle:
      layout: default
      modalid: 1
      date: 2014-07-18
      img: blah.jpg
      thumbnail: blah.jpg
      alt: image-alt
      projectdate: April 2014
      client: Start Bootstrap
      category: test text
      description: test text
    - title: Auto
<insert form2 here>
      subtitle:
      layout: default
      modalid: 2
      date: 2014-07-17
      img: test2.jpg
      thumbnail: test2.jpg
      alt: image-alt
      projectdate: April 2014
      client: Start Bootstrap
      category: test2
      description: testtext 2

How could I do this?

You wrote modal, I assume you mean “modal” and not “modular”, right?

In any way, the concept is the same. Multiple forms can be defined in the page, and then you include the form in your Twig, specifying which form it should display.

In your case, you can define in that page header:

forms:
    form1:
        fields:
            ...
        buttons:
            ...
        process:
            ...

    form2:
        fields:
            ...
        buttons:
            ...
        process:
            ...

Then add formname in each portfolio item, and enter for example form1. In the portfolio Twig, if portfolio_item is the variable you iterate on, add

{% include "forms/form.html.twig" with { form: forms(portfolio_item.formname) } %}

That should work!

Thank you very much Flavio, I will try this. I think grav is brilliant in its architecture and elegance. I look forward to using, learning, and increasing the adoption of grav!

1 Like