Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:52:33+00:00 2026-06-06T16:52:33+00:00

Would anyone please advise how in jade for nodejs I can truncate a string

  • 0

Would anyone please advise how in jade for nodejs I can truncate a string to a number of characters/words, ideally conscious about the HTML markup within the string?

This should be similar to Django’s truncatechars/truncatewords and truncatechars_html/truncatewords_html filters.

If this doesn’t exist in jade, which way is right to go? I’m starting my first nodejs+express+CouchDB app, and could do it within nodejs code but it seems that filters are much more appropriate.
I would also consider writing a filter like this (and others) if I knew how :))

Just a quick illustration:

// in nodejs:
// body variable comes from CouchDB
res.render('home.jade', { title : "test", featuredNews : eval(body)});

// in home.jade template:
    ul.thumbnails
    each article in featuredNews.rows
        a(href="#"+article.slug)
            li.span4
                div.value.thumbnail
                    img(align='left',src='http://example.com/image.png')
                    p!= article.value.description:truncatewords_html(30)

So I’ve made up the truncatewords_html(30) thing to illustrate what I think it should be similar to.

Will appreciate any ideas!

Thanks,
Igor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:52:36+00:00Added an answer on June 6, 2026 at 4:52 pm

    Here is a little “truncate_words” function:

    function truncate( value, arg ) {
        var value_arr = value.split( ' ' );
        if( arg < value_arr.length ) {
            value = value_arr.slice( 0, arg ).join( ' ' );
        }
        return value;
    }
    

    You can use it before sending the string to the template, or in the template using a helper method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please advise what is the best to achieve the below: Requirement: Drop
Could anyone please advise me what would be the best way to display the
Would anyone please be able to tell me the most efficient way to compare
Can any one please advise me how I can get the current count of
I am just wondering if anyone would be able to advise me how should
Can anyone please recommend the best way to trigger a horizontal Jquery scroller using
Could anyone please advise on the best method to detect whether a site is
Would anyone know why the bmlabel is not updated? and the log score shows
Would anyone be able to tell me how to pull the server name out
Would anyone offer tips, links, code snippets on how to browse to a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.