How to access a base object from Twig FormView in a template?

I have a ParamterValue class that references the ParamterDefinition class, by the ParamterValue-> paramDef property. I created ParamerValueType to create the form.

How can I access the ParameterValue-> paramDef object in a template? I just need this for some logic when rendering the form, in fact I don't need to display ParameterDefinition, so I do not include the paramDef form field in ParamterValueType. Even if I wanted to, how could I access the underling object from the form view field?

So, the general situation looks like this: I have an object that I want to create from a form, this object has a link to another object that has the data needed to render the form (but I do not need a widget for it, just some data to execute logic). Do I need to include this object in the ParameterValueType object to access it or not?

+6
source share
2 answers

You can usually just

{{ form.vars.data.paramDef }} 

Actually, this only works with Symfony 2.1.

+22
source

I do not quite understand what you are trying to do, but I think that creating a form extension or using global vars will bring you there.

Take a look at

http://toni.uebernickel.info/2011/11/25/how-to-extend-form-fields-in-symfony2.html

to learn about form extensions and

http://blogsh.de/2012/01/04/how-to-write-host-aware-twig-templates-in-symfony/

to learn about global vars.

0
source

Source: https://habr.com/ru/post/905287/


All Articles