How to show a defined form from PHP

I have a plugin with some custom logic of what to display on a page, and I would like to show a form which I have defined for that page given a certain condition. Basically, how do I do this twig bit in PHP:

{% include "forms/form.html.twig" with { form: forms('form-conditional') } %}

Dumping everything (grav), I can only find the form in the Page object… is it even possible?

@Netzhexe, Not exactly sure what you are trying to achieve, but…

You can do:

# variable = set by plugin
{% include "forms/form.html.twig" with { form: forms(variable) } %}


# variable = set by plugin
{% include "forms/form.html.twig" with { form: forms({'route': variable }) } %}

Ah, I did not make myself clear. But I solved it by myself! :slight_smile: This is my page markdown (feels super inelegant, but I’m pressed for time and nobody has admin access apart from me):

[some text content here]
{% include "forms/form.html.twig" with { form: forms('form-vote') } %}

<div class="print">
    <h2>Your vote</h2>
{% set voted = showvotes(grav.user.username) %}
{% if voted %}
{% include "forms/form.html.twig" with { form: forms('form-conditional') } %}
{% endif %}

I simply made my showvotes function return true or false, and I can use that in the twig, so all is well! :smiley: