I'm putting together a module that inlcudes pretty URLs generated from an entry title. So if I have a entry called "About about earwigs" then I'd end up with something like:
/newmodule/13/12/all-about-earwigs
It occurs to me that we must do this kind of slug creation somewhere when we create aliases, but having skimmed through the api docs I couldn't see anything obvious.
It's not a big deal if not because it's only a few lines to create my own function, but hey, I like to reuse code if it's there.
[SOLVED] Is there a built in function for creating a slug?
[SOLVED] Is there a built in function for creating a slug?
Last edited by scooper on Fri Jun 27, 2014 10:58 am, edited 1 time in total.
Re: Is there a built in function for creating a slug?
You can check News module as an example » action.default.php
and
Code: Select all
$prettyurl = $row['news_url'];
if( $prettyurl == '' ) {
$aliased_title = munge_string_to_url($row['news_title']);
$prettyurl = 'news/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title";
Code: Select all
$onerow->morelink = $this->CreateLink($id, 'detail', $detailpage!=''?$detailpage:$returnid, $moretext, $sendtodetail, '', false, false, '', true, $prettyurl);
[SOLVED] Is there a built in function for creating a slug?
Excellent - thanks for that Jos - munge_string_to_url is exactly what I was after.