XF 2.2 Anyone know how the xenforo URL slugs are generated?

XboxUnlimited

Active member
I was just wondered how xenforo generated the url slugs -

for example the "Have you seen ?" forum url is /have-you-seen

how is that generated, is there a function built in that does that, can is be used on custom pages?

Hope that makes sense

Thanks
 
I use this on a custom add-on of mine, in the controller, to turn content titles into URL slugs: $contentSlug = $this->app()->router->prepareStringForUrl($contentTitle);

The actual function is here: \XF\Mvc\Router::prepareStringForUrl($string, $romanizeOverride = null)
 
I use this on a custom add-on of mine, in the controller, to turn content titles into URL slugs: $contentSlug = $this->app()->router->prepareStringForUrl($contentTitle);

The actual function is here: \XF\Mvc\Router::prepareStringForUrl($string, $romanizeOverride = null)
Thanks that's a great help, getting somewhere now. Is it possible to call the "prepareStringForUrl" function from within a template?
 
Thanks that's a great help, getting somewhere now. Is it possible to call the "prepareStringForUrl" function from within a template?

I'm honestly not sure on that one but I'll mess with it a bit this weekend and, assuming someone else doesn't answer before me, I'll try to let you know before the weekend is up.

Until then, is there a specific reason why you can't just pass the string from the controller to the template using view params?
 
I'm honestly not sure on that one but I'll mess with it a bit this weekend and, assuming someone else doesn't answer before me, I'll try to let you know before the weekend is up.

Until then, is there a specific reason why you can't just pass the string from the controller to the template using view params?
Thanks, I just need to get my head around how this works so it's probably a lot to do with me.

So what I am working on is on this page https://www.xboxunlimited.com/games/ I want to make each tile clickable and go to a information page for each title, so the first thing I was experimenting with was creating a slug for each title.

At the moment the title string isn't viewable in the controller, the controller just generates the filter options to choose which items display on the template.

Don't know if that makes any sense, I suspect I am going about this the wrong way.
 
Thanks, I just need to get my head around how this works so it's probably a lot to do with me.

So what I am working on is on this page https://www.xboxunlimited.com/games/ I want to make each tile clickable and go to a information page for each title, so the first thing I was experimenting with was creating a slug for each title.

At the moment the title string isn't viewable in the controller, the controller just generates the filter options to choose which items display on the template.

Don't know if that makes any sense, I suspect I am going about this the wrong way.

This sounds like something you'd want to add into a database where each game would be listed in the database with a game_id and game_title, along with other info that will help populate these info pages. If you did that, you'd use routes that would format the links to the pages just like forums (ex. /games/7-days-to-die.123).

Anyways, that's just how I'd do it. As I said, I'll mess with things this weekend and let you know if I can find a way to use that function inside a template.
 
Forum slugs aren't generated, they're defined when you edit the node and set one manually. The node title that you see when you haven't set up an explicit slug doesn't carry any information and can be changed or removed without changing the validity of the URL, only the ID is relevant in that case.

If you want your route to accept a parameter, you need to declare it in the ACP route setup. You can either choose to use an integer param and declare an additional entity column that will be used for the (irrelevant) string bit in addition, or a string param if you want a true slug that carries information. Either way you'll have the desired param available in your ParameterBag in the controller afterwards. To generate a url from your entity, just use {{[link('my-route', $entity) }} in the templater or $this->buildLink('my-route', $entity) in the controller.
 
Top Bottom