I have defined constant in my entity like:
$fieldName = User::METADATA_OF_USER
It's passed as the entity getter param:
public function getMetaDataField($fieldName)
{
$metadata = json_decode($this->metadata, true);
return $metadata[$fieldName] ?? null;
}
When I try to pass it in twig:
{ item.metadataField }}
it requires that fieldName param as constant.
I tried some solution of twig constants but non of them worked for me. I there any way to inject that constant in the view?
According to Twig documentation, you need to use the
constant
function :Note the
\\
.