Page 1 of 1

[SOLVED] Is there a built in function for creating a slug?

Posted: Fri Jun 27, 2014 9:20 am
by scooper
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.

Re: Is there a built in function for creating a slug?

Posted: Fri Jun 27, 2014 10:09 am
by Jos
You can check News module as an example ยป action.default.php

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";
and

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?

Posted: Fri Jun 27, 2014 10:30 am
by scooper
Excellent - thanks for that Jos - munge_string_to_url is exactly what I was after.