2

What is slug and why it is used. I'm confused with it. Can anyone help me on it. Thanx

 <p><a t-attf-href="/academy/{{ slug(teacher) }}">
     <t t-esc="teacher.name"/></a>
Ravi Singh
  • 307
  • 2
  • 13

3 Answers3

3

I think it works for removing special characters from a string.

In addons>web>static>lib>underscore.string.js

slugify: function(str) {
      if (str == null) return '';

      var from  = "ąàáäâãåæăćęèéëêìíïîłńòóöôõøśșțùúüûñçżź",
          to    = "aaaaaaaaaceeeeeiiiilnoooooosstuuuunczz",
          regex = new RegExp(defaultToWhiteSpace(from), 'g');

      str = String(str).toLowerCase().replace(regex, function(c){
        var index = from.indexOf(c);
        return to.charAt(index) || '-';
      });

      return _s.dasherize(str.replace(/[^\w\s-]/g, ''));
    },
Terrence Poe
  • 634
  • 4
  • 17
2

Transform a string to a slug that can be used in a url path.

Example:(takem from the website tutorial).

<a t-attf-href="/academy/{{ slug(teacher) }}">
    <t t-esc="teacher.name"/>
</a>

You can find more details in slug function documentation.

Transform a string to a slug that can be used in a url path.

This method will first try to do the job with python-slugify if present.

Otherwise it will process string by stripping leading and ending spaces,

converting unicode chars to ascii, lowering all chars and replacing spaces
and underscore with hyphen "-".

Kenly
  • 24,317
  • 7
  • 44
  • 60
2

The slug function transforms the parameter(string) to a slug which can be used in a url path. E.g.:

consider teacher = teacher(1)

then <a t-attf-href="/academy/{{ slug(teacher) }}">

gives <a href="/academy/teacher-1">

Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42
Yassir Irfan
  • 223
  • 2
  • 6