Page.find not working in form data template to send email

I have a custom form with ajax submission on my site and it works great. Handling the response on the site I’m able to use a template and find.page works as it should, I can pull data from wherever I want on the site. When I need to send an email I’m doing the same on the data.html.twig template, but find.page doesn’t seem to work at all. Is there a particular reason for that or should I do something different?

This is how I use it:

{% set child = page.find("/machinery/automatic/" ~ subfolder ~ ‘/’ ~ value) %}

works on the form template, but not on the email body included template.

1 Like

I have same issue. My theory is that the page object is not available in the email body template because there is no page (md file), hence page.find doesn’t work.

I also tried the pages.find method, but it didn’t work either.

Yes, that could very much be the case, I also tried pages.find but no luck.
Did you find a workaround on how to access the data you need?

Yes, I just put it into site.yaml. In our it was actually more logical place than a page. But I would still like to learn how to read page’s header data from anywhere

Interesting, how do you access site.yaml? so that means we have access to site, as well as grav variables, but not pages. In my case I had to access pages images so it was easier to just put the same images in the theme images folder.

Hi, this discussion is long ago, but it was not presented a solution.

Since I ran into the same problem, I started a lot of trial and error to include another page (in particular the custom email response to one of several registration forms on the site).

The page object is available via the form object: So the twig expression should looks like:

{% set child = form.page.find(“/machinery/automatic/” ~ subfolder ~ ‘/’ ~ value) %}

Best wishes

1 Like

@macyogi, It might be better to create a new post with your context. The former OP will probably no longer be around to mark it as solved when a solution gets provided. You might add a link to the new post.

Thank you for the suggestion.
Like @pamtbaau said, it’s been a long time, I’ve found a different solution to the problem and I don’t even remember what I did, to be honest. But I’ve marked that as solved, could be helpful for another time or someone else, although I can’t really try if it worked in my situation anymore.