Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:07:49+00:00 2026-06-13T20:07:49+00:00

So I have been trying to work out this one for a while. In

  • 0

So I have been trying to work out this one for a while.

In PHP it is enough to first say if isset($var) and $var == something and it won’t complain about me trying to compare something that doesn’t exist.

Clearly that’s not enough in TWIG.

Now, why does this not work? I first run an if to check whether entity.container is set, and if it isn’t dont go through that block.

It seems that TWIG just HAS to go through all code anyways. So, I have this entity that doesn’t always have a container (entity.container) set, so how should I go about this? Because when I run this code TWIG just complains that I have one if statement where I try to go entitiy.container.containerType when entity.container doesn’t exist.

{% if entity.container is defined %}
    {% if entity.trash == false and entity.container.containerType.name =='Module' %}
        <form action="{{ path('deleteContent', { 'id': entity.id }) }}" method="post" onsubmit="return confirm('Bekräfta att du vill radera detta innehåll? Detta går inte att ångra.')">
            {{ form_widget(delete_form) }}
            <button type="submit" style="color:red;">Radera permanent</button>
        </form>
    {% elseif entity.trash == false and entity.container.containerType.name !='Module' %}
        <form action="{{ path('deleteContent', { 'id': entity.id }) }}" method="post">
            {{ form_widget(delete_form) }}
            <button type="submit" style="color:red;">Flytta till papperskorgen</button>
        </form>
    {% elseif entity.trash == true and entity.container != null %}
        <form action="{{ path('restoreContent', { 'id': entity.id }) }}" method="post">
            {{ form_widget(delete_form) }}
            <button type="submit" style="color:red;">Återställ till ursprunglig plats</button>
        </form>
    {% else %}
        För att återställa detta innehåll måste du först välja en plats för det.
    {% endif %}
{% else %}
hehe
{% endif %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:07:50+00:00Added an answer on June 13, 2026 at 8:07 pm

    I think that in your case, the entity.container is defined but is not set, may be null.
    There is a difference between a defined and an empty or null variable.

    So the first if statement is checked and allow to parse the logic inside.

    To check if a variable is set or not you’ve to use

    {% if entity.container %}
    

    or simply use the “is not null”,

    {% if entity.container is not null %}
    

    both with the condition that the variable should be defined, otherwise you’ll get the error “Item or Object “container.whateverYouWant” for “entity” does not exist …”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I been trying to work this out but unable too. I have a
I have been pulling my hair out trying to make this work. I have
I was wondering if someone could work this one out as I've been trying
I have been trying for quite a while to work out how to accomplish
I've been online for days trying to figure this one out and, while I've
I have been trying to get this to work correctly and I think I
I have been trying to get this jsfiddle to work. So far without luck.
This is crazy, I have been trying for hours to get this to work.
I've been trying all sorts to get this to work, I have a table
I have been trying to work with the Projector and Ray classes in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.