简体   繁体   中英

Truncate a post.excerpt

I am trying to truncate a post.excerpt .

Actual code is <%- post.excerpt || post.content%> <%- post.excerpt || post.content%>

The above shows all of the intro text of a blogpost.

Now I want to truncate that intro text to 25 characters length.

The truncate code is like in this example:

<%- truncate('And they found that many people were sleeping better.', {length: 25, omission: '... (continued)'}) %>`

Now to combine that, I came up with:

<%- truncate((post.excerpt), {length: 25, omission: '... (continued)'}) || post.content%> 

But that did not work, how to make truncating work for my needs?

Full code here...

<section class="article typo">
    <%- post.excerpt || post.content %>
    <% if (post.excerpt) { %>
      <div class="readmore">
          <a href="<%- url_for(post.path) %>">Read More</a>
      </div>
    <% } %>

Instead of truncating content to excerpt, Try this

 `<section class="article typo">
      <%- post.content | truncatewords: 25 %>
      <div class="readmore">
      <a href="<%- url_for(post.path) %>">Read More</a>
    </div>
    <% } %>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM