0

I'm using the channel entries search parameter to filter entries based on the value in a segment. However, I've just spotted that some of these segments contain ampersands, and these don't work correctly when filtering channel entries in this way. Is there a way around this?

Here's an example URL that I'm having issues with: mywebsite.com/regions/Yorkshire & Humberside

The spaces work fine as they are automatically converted into %20, like this: mywebsite.com/regions/Yorkshire%20&%20Humberside, which seems to work fine in EE. But the ampersand doesn't get converted into anything, so my segment is being ignored after the ampersand, so my filtering isn't working correctly.

I've tried changing the ampersand to %26, like this: mywebsite.com/regions/Yorkshire%20%26%20Humberside but that doesn't make any difference. I've also tried changing the ampersand to & amp; (I've added a space here as EESE keeps converting this into an ampersand if I write it out correctly) like this: mywebsite.com/regions/Yorkshire%20& amp;%20Humberside, but that just gave me the following error: The URI you submitted has disallowed characters.

Here's what my channel entries tag looks like:

{exp:channel:entries channel="location" status="open" limit="1000" dynamic="no" search:cf_location_region="{segment_2}"}

Can anyone think of any workarounds to this? I can't use categories due to the way in which I'm getting the data from an external data source. Thanks.

1 Answer 1

1

Been testing this further and I found that the channel search parameter does seem to be working correctly, even with the ampersand in the URL.

The thing that was making me think it wasn't working correctly was the fact that the title at the top of the page, < h1>{segment_2}< /h1> was being cut off after the ampersand (like this: < h1>Yorkshire< /h1>, instead of outputting < h1>Yorkshire & the Humber< /h1>, so I assumed that the same issue was also be happening to the {segment_2} in the channel search parameter.

To work around the issue with the title being cut off with the segment variable, I'm using a Zoo Triggers variable to output the page title instead (< h1>{triggers:segment_2}< /h1>), and that outputs the full title correctly: < h1>Yorkshire & the Humber< /h1>.

I've no idea why the standard segment variable is being cut off after the ampersand, or why the Zoo Triggers variable works fine, but it's outputting what I want so I'll move on. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.