How to target a page created with collections via its slug

I’ve got a page, /external, that I’ve created with collections in the routes.yaml file:

    permalink: /{slug}/
    template: index
    filter: tags:-[hash-external]
        resource: posts
        type: browse
        filter: tags:[hash-external]
        limit: 3
    permalink: /{slug}/
    template: external
    filter: tag:hash-external
    controller: channel
    data: page.external

What I need to do with that page is not only target it with {{#is "page"}}{{/is}} (which works), but target it specifically via its slug so that other pages aren’t affected. However, things don’t work when I try and single things out via the following:

{{#is "page"}}
{{#has slug="external"}}

Am I just doing it wrong, and/or might there be some other way to accomplish this that I’m not thinking of?

There are a couple of things going on here.

In the routes file, are you using the data property on the /: route? If not, you can remove it, as it’s not essential to the collection, as far as I can tell. The controller property isn’t intended to be used on a collection—it’s just for routes, so you can remove it.

I think the reason that your has helper isn’t working is that you would need to be in the page context to be able to access the slug.

  {{#has slug="external"}}

However, you can do this with a 1-liner:

{{#is "external"}}
  Do your thing

This will only return true when on the external collection.

1 Like

Yes, both of your suggestions worked, thanks! The second is more concise and specific, so I went with that one.

1 Like