Search code examples
pugsubstr

How can I display just a part of a string with pug/jade?


I would like to display a number of 250 character of a text. p #{description} // display all the description How can I do this in pug ?

I try with substr or length but it does not work.

Thanks for help


Solution

  • Javascript methods like substr() can be easily used within Pug templates. You mentioned trying substr() but not being successful with it. Did your attempt look like this?

    p #{description.substr(0,250)}
    

    This should create a <p> with the first 250 characters of the description string, provided it exists and is a string.