Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access an underlying object from a Twig's FormView in a template?

Tags:

twig

symfony

I have a ParamterValue class which references ParamterDefinition class, by property ParamterValue->paramDef. I created ParamterValueType to build a form.

How can I access ParamterValue->paramDef object in a template? I just need it for some logic in rendering a form, I actually don't need to render ParamterDefinition, that's why I don't include paramDef form field in ParamterValueType. Even if I would, how could I access underling object from the form view field?

So the general situation here looks like this: I have an object which I want to create from a form, that object has a reference to another object which has data that are needed to render the form (but I don't need a widget for it, just some data to perform logic). Do I need to include that referenced object in ParamterValueType to get access to it or not?

like image 671
Dawid Ohia Avatar asked Jan 06 '12 09:01

Dawid Ohia


1 Answers

You can usually just do

{{ form.vars.data.paramDef }}

Actually, this only works as of Symfony 2.1.

like image 96
Bernhard Schussek Avatar answered Nov 15 '22 11:11

Bernhard Schussek