getgrav / getgrav/grav-plugin-form

Form email body with Twig include and 'with' clause, variables not available in included template

Open
#526 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
64
Forks
80
Avg merge
10h 13m
Merged PRs (30d)
9

Description

I'm trying to create an email body like:

```yaml
body: "Thank you for your message via my website. Here is a copy for your records:\n\n{% include 'forms/data.txt.twig' with {'hide_fields': ['ip', 'timestamp']} %}"
```
(I want to customise the formdata template to hide the fields named, that's kind of irrelevant except it shows a use case.)

I created theme copies from the form plugin `themes//templates/formdata.html.twig` and `themes//templates/forms/default/data.html.twig`.

It looks like my variable `hide_fields` is not being passed through and I tested this by adding `{{ dump(hide_fields ) }}` to `formdata.html.twig` and it dumped `null`.

I traced this back some way but eventually got lost. It looks like the email plugin's `Email->buildMessage()` calls `\Grav\Common\Twig\Twig->processString()`. When I dump the result there with PHP, it has been lost and I can't quite figure out where. My PHP debugging toolkit isn't that sharp. Just raising the possibility this is an issue in the email plugin or Grav core. Hope it helps.

Should my Twig expression in the email body be supported? I have a feeling I've even done this in the past, though I couldn't find it.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the email body from the issue using the theme copies at themes//templates/formdata.html.twig and themes//templates/forms/default/data.html.twig, including the dump of hide_fields. Trace Email->buildMessage() into \Grav\Common\Twig\Twig->processString() and identify where the include context is lost. Done means determining whether the Twig expression is supported and preserving hide_fields in the included template if it is.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.