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

Added option 'twig' to form field to evaluate label using twig.

Open NicoHood opened this issue 4 years ago • 2 comments

Example:

name:
    label: 'Name (See [documentation]({{ page.route }}))'
    placeholder: 'Your Name'
    autocomplete: 'on'
    type: text
    twig: true
    markdown: true

Combined with https://github.com/getgrav/grav/pull/3139 this becomes very powerful, as you can use theme_var('doc_route') to load url settings (and other stuff) here dynamically.

NicoHood avatar Jan 09 '21 18:01 NicoHood

This approach is a good and granular idea, however it will get very messy to implement. I think the core issue currently is the naming conflict evaluate vs twig.

In my PRs this means:

  • evaluate parses the default value using twig
  • twig parses the label field with twig, and text for sections

I think you are right: they should be named the same. What about "renaming" evaluate to twig and enable optional twig (and markdown) support for all static fields (no user interaction). This means twig would:

  • Make labels twig compatible
  • Make help texts twig compatible
  • Make default values twig compatible
  • Make any other static fields like text or title of section twig compatible
  • And it would let us keep backward compatibility for the hidden field (using evaluate instead of evaluate_twig), but also add the new twig name for the "better" evaluate_twig function

The name twig sounds correct here, as it is also used in pages via process.twig or process.markdown.

my_field:
  label: '**label** {{ page.title }}'
  default: 'also **markdown**'
  markdown: true
  twig: true

NicoHood avatar Jan 11 '21 12:01 NicoHood

Again, i'll take a look at this after the next release.

rhukster avatar Feb 16 '21 21:02 rhukster