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

  • Home
  • SEARCH
  • 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 6910419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:48:43+00:00 2026-05-27T08:48:43+00:00

It seem I have problem with a twig if statement. {%if fields | length

  • 0

It seem I have problem with a twig if statement.

{%if fields | length > 0 || trans_fields | length > 0 -%}

The error is:

Unexpected token "punctuation" of value "|" ("name" expected) in 

I can’t understand why this doesn’t work, it’s like if twig was lost with all the pipes.

I’ve tried this :

{% set count1 = fields | length %}
{% set count2 = trans_fields | length %}
{%if count1 > 0 || count2 > 0 -%}

but the if also fail.

Then tried this:

{% set count1 = fields | length > 0 %}
{% set count2 = trans_fields | length > 0 %}
{%if count1 || count2 -%}

And it still doesn’t work, same error every time …

So… that lead me to a really simple question: does Twig support multiple conditions IF ?

  • 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-05-27T08:48:43+00:00Added an answer on May 27, 2026 at 8:48 am

    If I recall correctly Twig doesn’t support || and && operators, but requires or and and to be used respectively. I’d also use parentheses to denote the two statements more clearly although this isn’t technically a requirement.

    {%if ( fields | length > 0 ) or ( trans_fields | length > 0 ) %}
    

    Expressions

    Expressions can be used in {% blocks %} and ${ expressions }.
    
    Operator    Description
    ==          Does the left expression equal the right expression?
    +           Convert both arguments into a number and add them.
    -           Convert both arguments into a number and substract them.
    *           Convert both arguments into a number and multiply them.
    /           Convert both arguments into a number and divide them.
    %           Convert both arguments into a number and calculate the rest of the integer division.
    ~           Convert both arguments into a string and concatenate them.
    or          True if the left or the right expression is true.
    and         True if the left and the right expression is true.
    not         Negate the expression.
    

    For more complex operations, it may be best to wrap individual expressions in parentheses to avoid confusion:

    {% if (foo and bar) or (fizz and (foo + bar == 3)) %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem understanding how to conditionally test a boolean value
I seem to have a problem - rather unexpected; so I guess I might
I seem to have a problem with this SQL query: SELECT * FROM appts
I seem to have a problem with getting MVC to fill in my custom
I have a problem which I cant seem to find answer to through searches
I have a problem, which I do not seem to be able to solve...
I seem to have the exact opposite problem than this question on stopping dock
I actually seem to have problem with this (only on linux, described here with
Seem to have a problem starting my Java app: Exception in thread main java.lang.NoClassDefFoundError:
I seem to have a problem that I can't find the solution for myself,

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.