Nechalon - Is there a way to get the current sl...
# ❓questions
n
Is there a way to get the current slug in the controller? $this->slug doesnt work
i
frontend controller or twill admin controller?
n
twill admin controller
i
which method?
n
formData, im trying to put together the customPermalink with the route and its slug
you can query your record from its id and then do ->slug
but before you do that, can you share your use case? you may be able to make it work without having to use customPermalink
If you only need to change the base path before the slug, you could use setPermalinkBase('example') in your setup method
n
I checked the link. The use case would simply be to have a working permalink for all of the controllers in the project. Because some are working and some are not, some have missing slugs etc etc. So it would be better to just change the permalinkBase, How would I set that up? Inside the formData? It shows an error to the setPermalinkBase() function. https://twillcms.com/docs/modules/controllers.html#content-setters
Copy code
public function setUpController(): void
    {
        $this->setPermalinkBase('example');

    }
It would be something like this? It doesnt seem to change the base of the url
i
Are you still sending customPermalink in formData?
remove it to see setPermalinkBase take effect
n
I have removed it, and it still doesnt change
i
what I meant by use case is whether you need more than eg. https://domain.com/permalinkBase/slug
what is the generated permalink if you don't do anything in your controller and what is the permalink you're looking for instead?
n
its /sr/blogPosts/{slug} and im looking for /blog/{slug}
since the slug is already there if I dont change the permalink, then it would be better to just change the base link
i
Try:
Copy code
protected $permalinkBase = 'blog';
protected function setUpController(): void
{
    $this->withoutLanguageInPermalink();
}
now, if you use multiple languages you don't want to disable the /sr from it, your frontend routing should redirect to without sr if that's how you want it configured
otherwise switching the language toggle in the form wouldnt update the permalink with, /en, for example
n
now the base url changed to 'blog', but the language is still there
i
Are you on twill 3?
n
yes, I just want it to be redirected without the language, otherwise I need translations
V2.3.0.
i
if you're not on twill 3 setUpController doesn't exist, so ignore that
n
oh, so thats why it has no effect
i
yea. so now you have the correct way of setting the permalink base. In my opinion keeping the language is correct, because your frontend should definitely route /sr requests to be redirected to without /sr. If you want to still do it but keep the language in the permalink, you could use getPermalinkBaseUrl()
n
Yes, it should be there if there are other languages, but the problem is that all pages are without the language link for now, so mb they/I will add it later, but for now it would be better to have the permalink without the /sr in it.
i
in that case implement getPermalinkBaseUrl and return something like route('blog')
n
where could I use getPermalinkBaseUrl? inside formData?
i
no, it's another method like form data
to add to your controller
n
okay, that removed the /sr, now I would just need to add a slash after the route
because right now it looks something like this `blog{slug}'
i
return it with what you returned in getPermalinkBaseUrl
n
okay, working.
Copy code
public function getPermalinkBaseUrl()
    {
        return route('blog') . '/';
    }
Thanks for your help @ifox 😄