Forum

Thread tagged as: Question, Problem

Search results urls with {braces}

Hi,

I have a doubt: in the options of a given collection, I fill the URL for single items so that I can add a link to the search results. The URL I'm adding in the options looks like this: /news/{news_date}/{slug}.

The problem is that in my template news_date refers to a formatted date <perch:content id="news_date" type="date" format="%Y" /> so the search url end-up like /news/2015-12-13/my-news.

Is there any way to format the braces so that it only output the year? If no, would you have a suggestion on how to overcome this?

Thanks.

Robin Pick

Robin Pick 5 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Off the top of my head - see if this works. Create a new composite field for just the year component:

<perch:content id="news_year" type="composite" join="news_date_year" suppress="true" />

And then use that in the URL:

/news/{news_date_year}/{slug}

Hi Drew,

I have tried your suggestion but it doesn't seem work.

I wonder what approach you took for 24ways for the search and how you structured the template of your collection for the date: https://24ways.org/search/?q=Test. When I click on a given search result, I do see the year in the url. Any chance you could point me at the direction you've taken?

Thanks,

Drew McLellan

Drew McLellan 2638 points
Perch Support