Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to add a function or parse "slugs"?
hasaezs Offline
Junior Member
**
Posts: 1
Joined: Nov 2014
Post: #1
How to add a function or parse "slugs"?
Good!

I need help to add a function that converts strings in "slugs" function and have the write down, but do not know where to add that this is recognized by "Template Conditionals".

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
function slugify($text) { 
  $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  $text = trim($text, '-');
  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  $text = strtolower($text);
  $text = preg_replace('~[^-\w]+~', '', $text);

  if (empty($text)) {
    return 'n-a';
  }

  return $text;
}


Any idea how to do this?

Greetings and thanks.

11-14-2014 09:33 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: How to add a function or parse "slugs"?
Can't be done with Template Conditionals, but PHP in Templates should work.

Or, if you have the function already included somewhere, and it's already reference-able globally across MyBB, and just want to be able to reference it from Template Conditionals, modify inc/plugins/phptpl_allowed_funcs.txt

My Blog
(This post was last modified: 11-16-2014 07:48 PM by ZiNgA BuRgA.)
11-16-2014 07:46 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: