grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

Print Twig in form field

Open bluis4 opened this issue 4 years ago • 1 comments

Hi,

is it possible to print twig variable (something like page.header.title) inside a form field ?

for example :

---
title: A Page with an Example Form
form:
    name: contact-form
    fields:
        - name: name
          label: Name
          placeholder:  {{ page.header.title }}
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true

    buttons:
        - type: submit
          value: Submit
        - type: reset
          value: Reset
---

bluis4 avatar Apr 24 '20 20:04 bluis4

Take a look at Using Function Calls (data-*@)in the Grav documentation. I've never used this method with the placeholder field property but in theory it should work as it works with the label property. There's also a plugin which might help, see Form Prefiller Plugin.

bleutzinn avatar Aug 20 '20 20:08 bleutzinn