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 3481256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:25:46+00:00 2026-05-18T10:25:46+00:00

I am experiencing weird behavior with template toolkit, say I have a data structure

  • 0

I am experiencing weird behavior with template toolkit, say I have a data structure (defined in perl and passed as a parameter):

( { FLAG => 1, some => data}, { some => data}, etc )

and in a template I have a loop like

[FOR ITEMS]
  [IF (FLAG) ]
    do something
  [ELSE]
    do something else
  [END]
[END]

the template seems to never enter the else, the only way I can get it to enter the else is to change the data:

( { FLAG => 1, some => data}, { FLAG => 0, some => data}, etc )

so that it evaluates to false.
However if I then change the data structure to

( { some => data}, { some => data}, etc )

It always enters the else (because it evaluates undef to be false).

It seems as if there is some ‘bleed over’ of variables remaining in scope for the next iteration unless they are overwritten, is this expected behavior? and if so is it documented anywhere?

EDIT:
Later on I found it was a different issue causing the above behavior, it was due to me using “ELSEIF” and not the correct “ELSIF” elsewhere in the template.
If in doubt check out the solution proposed by jira which solved the problem I described in my origional post.

  • 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-18T10:25:47+00:00Added an answer on May 18, 2026 at 10:25 am

    You can modify the template like below assigning the loop variable to a named hash. Then it will behave as you expect.

    [%FOREACH ITEM IN ITEMS%]
    
      [%IF ITEM.FLAG %]
        do something
      [%ELSE%]
        do something else
      [%END%]
    
    [%END%]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing a weird behavior by Scala handling of superclass constructors. I have
I'm experiencing really weird behavior with the Socket.Connect method in C#. I am attempting
I'm currently working with jQuery 1.4.2 and jQuery UI 1.8.2. I'm experiencing some weird
Using PHP 5.3 I'm experiencing weird / non-intuitive behavior when applying empty() to dynamic
This is the day of weird behavior. We have a Win32 project made with
I am working on an Orbited -powered website and I'm experiencing some annoying behavior
i am experiencing some weird behaviour here. i am using the following code to
I'm experiencing some weird behaviour when using a ASP.NET LinkButton with a OnClientClick-property. ASPX
I am experiencing some weird encoding behaviour in my ASP.NET MVC project. In my
I was experiencing some weird behaviour in some of my javascript code, but only

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.