Custom Content Category Routing

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
TCR_500
Registered User
Posts: 175
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Custom Content Category Routing

Post by TCR_500 » Fri Feb 09, 2018 5:15 pm

I'm trying to develop an extension that categorizes content somewhat like how the forum navigation work, but with the category names appearing in the URL in addition to what is shown in the navigation bar. For example:

What the URL should look like:
category\name\content
category-name\content
other\category\name\content

And the navigation bar would be:
Category < Name < Content
Category Name < Content
Other < Category < Name < Content

The documentation doesn't seem to cover this. So how do I get the URL routing to behave the way I want it to?

I tried something like this, but it didn't work:

Code: Select all

acme_demo_index:
        path: /custom
        defaults: { _controller: acme.demo.controller:handle }
acme_demo_viewcategory:
        path: /custom/{categories}
        defaults: { _controller: acme.demo.controller:handle }
acme_demo_viewcontent:
        path: /custom/{categories}/{name}
        defaults: { _controller: acme.demo.controller:handle }
EDIT: I also couldn't find anything from the search results.

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Custom Content Category Routing

Post by posey » Sat Feb 10, 2018 1:27 pm

What does not work?
When you go to that path, the handle($categories, $name) function is called in your controller. And depending on the variables (categories and name) you can display your page.
What you could do, not sure if its necessary, but is add defaults for the variables.

Code: Select all

acme_demo_index:
        path: /custom
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
acme_demo_viewcategory:
        path: /custom/{categories}
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
acme_demo_viewcontent:
        path: /custom/{categories}/{name}
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

TCR_500
Registered User
Posts: 175
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Re: Custom Content Category Routing

Post by TCR_500 » Sun Feb 11, 2018 11:11 pm

posey wrote:
Sat Feb 10, 2018 1:27 pm
What does not work?
When you go to that path, the handle($categories, $name) function...
That explains a few things. But I'm not sure how I'd distinguish between category and content when a link is clicked or typed into the URL bar.

This will take some time for me to try-out, then I'll post back.

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Custom Content Category Routing

Post by posey » Mon Feb 12, 2018 8:12 am

So if someone is going to your route, .../custom/awesome/stuff.
Then in your function handle($categories, $name), $categories = 'awesome' and $name = 'stuff'. So you can do your magic there.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests