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-contractorthe 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-contractorI 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?
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.