We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Contains operator (*=) not working - HELP!

How Do I?

jay_turley's avatar
jay_turley
46 posts
10 years ago
jay_turley's avatar jay_turley

I’m trying to redirect certain search results to a single URL. If search results return an entry from the faqs channel, I want the link to go to the main faqs page, instead of to a detail page. To accomplish this, in my template, I have the following code:

{if auto_path *= "/about/faqs/"}
  <strong><a href="http://{path=about/faqs}">{title}</a></strong>
{if:else}
  <strong><a href="http://{auto_path}">{title}</a></strong>
{/if}

The *= operator is never triggered. Every link comes out as the auto_path even when it should be triggered.

For example, given an autopath of:

http://mysite.org/index_new.php/about/faqs/are-we-a-contractor

the expected href is

http://mysite.org/index_new.php/about/faqs/

but it is invariably rendered as

http://mysite.org/index_new.php/about/faqs/are-we-a-contractor

I have the contains operator working correctly in my layout, so I know it works (although it breaks if the not operator (!) is used, so I had to reverse my logic to do the positive case first to make the layout work, i.e. {if ! my_var *= "asdf"} won’t evaluate correctly, but {if my_var *= "asdf"} will).

Any thoughts on what might be going on here?

       
jay_turley's avatar
jay_turley
46 posts
10 years ago
jay_turley's avatar jay_turley

For posterity:

Turns out the issue in this case was using a variable in the Search Results URL.

I was using an (undocumented)

{homepage}/template_group/template/

format for my Search Results URL. This meant that {auto_path} wasn’t parsed in time to do any conditional checks on it in the search results template.

This meant that trying to do things like:

{if "{auto_path}" *= "about/faqs"}

or

{if "{auto_path}" ~ "[arbitrary regexp]"}

flat out failed, and those conditional branches were never followed.

In order for {auto_path} to be used with the EE comparison operators, the Search Results URL must be hardcoded to the actual site URL. So I replaced

{homepage}/about/faqs/

with

http://mysite.org/index_new.php/about/faqs/

and everything worked as expected.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.