packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello

Does anyone know who one might search a list in Templates?
That is, I have inherited an application that creates a template variable called SEARCH_RESULTS. This contains many arrays some with other arrays. If I do the following in the template:

[% FOREACH line in SEARCH_RESULTS %] [% line.fieldoffice %] [% END %]
I get the value of the fieldoffice list. Sometimes this value has one entry and displays like "Office1". Other times it shows: "Office2 , Office9 , Office11".
Does anyone know how I might write an IF statement to search the result to find the existance of a specific element?
I want to do something if, say, "Office 10" exists.
I have tried looking at the Vmethods but I just can't get my head around them

Replies are listed 'Best First'.
Re: Templates array grep?
by stonecolddevin (Parson) on Jan 25, 2012 at 20:28 UTC

    I'm inclined to think that this sort of logic should go in a model, not a view. IE, not in your template.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

Re: Templates array grep?
by ww (Archbishop) on Jan 25, 2012 at 19:47 UTC
    have you considered testing the return code with eq or a regex?