Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

NicoHood
Copy link
Contributor

@NicoHood NicoHood commented Jan 9, 2021

Example:

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

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

@mahagr mahagr requested a review from rhukster January 11, 2021 09:41
Copy link
Member

@mahagr mahagr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise I do not object, but both form.markdown and form.twig parameters now doing two things which are not related to each other. Also what if I want description to be markdown?

These parameters should really be all renamed with some deprecation message for people who still use the old ones.

IMHO the best approach would be to pass an array:

my_field:
  label:
    text: My Label
    markdown: true
    twig: true

while still allowing the value to have a string for a shortcut.

@rhukster What do you think?

@NicoHood
Copy link
Contributor Author

NicoHood commented Jan 11, 2021

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

@rhukster
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants