Is there a way to manually choose your slug for a page’s tinyurl?
No, but you could create a simple redirection template and set up the desired slugs as redirections to the pages you want.
Yeah, I have a redirection template already, so that’s potentially possible. One more step. It would be nice to just put the slug in a tinyurl field or something.
This should be possible with a custom route. You can search for the page with the correct value in the tinyurl field and than go to this page.
Ooh, good idea. I’ll pursue that.
More important things have taken my time. I’ll try to work on this soon, though.
So the custom route was almost too easy.
c::set('routes', array(
array(
'pattern' => 't/(:all)',
'action' => function($slug) {
$page = site()->index()->findBy('tiny', $slug);
go($page ? $page->url() : 'error');
}
)
));
- Notice I used
t
as my folder name. I left the standard kirby functionality asx
. - Looks in the index for a page with a field
tiny
with a value that matches whatever comes aftert/
in the URL. If it doesn’t find it, it throws a 404. - Now in the header (or anywhere I display a tiny url on the page) I’ll check for this field and display a URL that matches. If the field is empty, I’ll display the standard kirby shorturl.
That’s really cool! I built a TinyURL field and I’m thinking of a way to integrate the functionality you described here as part of that field. How would you do it?
I haven’t really played with custom portal fields. My simple method doesn’t actually replace that tinyurl. It would basically be a secondary field that would override it. Well, not even override it. Both would still work.
Sort of like having two fields side by side:
Default tinyurl / Custom tinyurl.
That’s a thought!