I’m using the form plugin to save user generated html from submitted data. Below is the default data.html.twig code that generates these pages in the form plugin.
I’d like to add the current users $username to the page thats generated. Could anyone be so kind as to explain how to go about doing that?
‘’’
{% for index, field in form.fields %}
{% set input = attribute(field, “input@”) %}
{% if input is null or input == true %}
{% block field %}
If it helps, or is more effeciant I’ve created the twig plugin that allows me to Output some PHP code result in a Twig or md template. which is currently the example string 'something;.
<?php
namespace Grav\Plugin;
class AddUsername extends \Twig_Extension
{
public function getName()
{
return 'AddUsername';
}
public function getFunctions()
{
return [
new \Twig_SimpleFunction('example', [$this, 'exampleFunction'])
];
}
public function exampleFunction()
{
return 'something';
}
}
Given the above a good go in different ways, but It’s not working:
My Form
{{ config.system.pages.theme }}
my name is: {{ grav.user.username }}
^ The twig above is being processed because the theme is returning antimatter, but the username is returning empty. (My username is set to David on the admin panel.)