Forum

Thread tagged as: Question

Collection URL for single items?

Hi,

I've almost got search implemented, but I'm having problems getting search results from a collection to link to the correct detail page.

I've turned on perch:showall on my collection detail page and I can see url_0 displays the full URL to the detail page.

I was hoping to use {url_0} in the URL for single items field in collection options, but it's not working?

Is there a recommended way to get search results from a collection working?


Summary information

Perch Runway: 3.1.2, PHP: 7.1.12, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Darwin, cgi-fcgi
Installed apps: content (3.1.2), assets (3.1.2), categories (3.1.2), perch_blog (5.6.1), perch_forms (1.12)
App runtimes: <?php $apps_list = [ 'perch_forms', 'perch_blog'  ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/user-name/Repositories/project-name/cms/perch
PERCH_CORE: /Users/user-name/Repositories/project-name/cms/perch/core
PERCH_RESFILEPATH: /Users/user-name/Repositories/project-name/cms/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/
DOCUMENT_ROOT: /Users/user-name/Repositories/project-name/cms
HTTP_HOST: project-name.local
Stephen Meehan

Stephen Meehan 4 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Stephen,

You'd normally use id="result_url" for search result URLs. It should use the URL for single items you've set in the control panel.

Hi Hussein,

Yes, I'm using the default search-result.html template.

The value added to the URL for single items field in collection options populates id="result_url"

As a test, I can add a static URL in the URL for single items field in collection options.

This then becomes the URL for any search results from that collection. But of course the value needs to be dynamic.

It'd be ideal if I could use the value in the ID url_0 as that outputs the full path to the detail page.

I was just wondering how other developers handle this (common?) issue :)

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

What are you adding for the URL for single items? It can be dynamic. For example, you can use /events/{slug}.

I've tried a number of things in the URL for single items field.

Ideally, I need the entire URL to be dynamic. Unfortunatley, this doesn't work, the output is blank: {url_0}

This particular website is multi language, uses multiple collections and each collection has many categories. A rather large website. :)

This is an example of a typical collection detail page URL /en/rail-technologies/solutions/friction-management/hydraulic-lubricators

I can partially get it to work by adding {solution_slug} to the end of the URL (in the URL for single items field).

/en/rail-technologies/solutions/friction-management/{solution_slug}

I need to add {braces} to every part of the URL, not just the end.

The detail page <perch:showall> lists lots of IDs that should allow me to create a dynamic URL, but many of the IDs don't work in {braces}. I can only assume many of the IDs aren't available on the search page...

For example, there's url_1 which is the name of the category (friction-management). I thought I could do this:

/en/rail-technologies/solutions/{url_1}/{solution_slug}

But it doesn't work? Hmmmm.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

url_0, url_1, etc won't be useful in there as they are not really data available for the item. They're available for you on the page. So not everything you see on the detail page with perch:showall is available to you in this case.

What does friction-management represent in your item template? Is it a category field?

What does friction-management represent in your item template? Is it a category field?

Yes, it's a category field. Can it be used in {braces} somehow?

The URL can be broken down like this

/en/rail-technologies/solutions/friction-management/hydraulic-lubricators
/page/page/solutions/category/detail_slug
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

I don't think so. You can select multiple categories in a category field so I don't see that working.

Hi Hussein,

Thanks for taking the time to reply, really appreciate it.

Yeah, I guess the way URL for single items setting is designed to work is to hardcode the full path and end it with a {slug}

For most sites that'll work fine. It's just unfortunate for this particular project the detail page of a collection can be in five different places. Plus the surrounding links/sidebar are different depending on where the user is in the website.

So hardcoding up the {slug} doesn't really work.

Hmmmm, back to the (virtual) drawing board.

For most sites that'll work fine. It's just unfortunate for this particular project the detail page of a collection can be in five different places. Plus the surrounding links/sidebar are different depending on where the user is in the website. https://snaptube-downloadapp.com/ https://popcorntimeapk.org/

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

There's always workarounds, Stephen.

For instance, you can set the URL for single items to something shared among all items like /rail-technologies/search/solutions/{solution_slug} and that page redirects to the URLs you actually want.