1

This is a follow up question to this one . What I want to know is how to check if the entity variable exist/is defined/not null. I thought I could do this:

{% if entity.orgId is defined %}
{{ render(controller(
    'CompanyNameofBundle:OrgMember:test', {'orgid':entity.orgId})) }}
{% endif %}

But if entity.orgId is null I get an exception has been thrown during the rendering of a template ("The product does not exist").

Community
  • 1
  • 1
shayster01
  • 214
  • 3
  • 17

3 Answers3

1

Change your controller to return null instead of exception:

public function testAction($orgid = null) {
    if (!$orgid) { return null; }
// Rest of code.
}
malcolm
  • 5,486
  • 26
  • 45
0

You have two options:

  1. Don't call the render controller using the check

    {% if entity.orgId is defined and entity.orgId is not null %}
    
  2. Make the testAction in the OrgMemberController null-safe (check if the parameter orgid is null)

der_michael
  • 3,151
  • 1
  • 24
  • 43
rudihaus
  • 43
  • 5
  • 1) Doesn't work still gets the same An exception has been thrown during the rendering of a template ("The product does not exist") . 2) I can't do that because I still need the object. The render controller requires that parameter though to function. – shayster01 Aug 28 '15 at 22:14
0

Try this:

{% if entity.orgId is defined %}
    {% if entity.orgId is null %}
        {# do something #}
    {% else %}
        {# do anythingelse #}
    {% endif %}
{% endif %}
Emmanuel HD
  • 191
  • 7
  • This is the same answer as the one above except you have broken it into two for loops. – shayster01 Aug 31 '15 at 14:11
  • There is a litle difference, i used `is null` instead `is not null` – Emmanuel HD Aug 31 '15 at 14:44
  • That is pretty in material in any case the is issue had to be checked in the controller because since it was never set to null it wasn't returning anything other than an error. – shayster01 Aug 31 '15 at 14:46