# Limit the {{ .Summary }}

**URL:** <https://discourse.gohugo.io/t/limit-the-summary/4103>\
**Category:** support\
**Created:** [September 15, 2016, 2:09pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103 "2016-09-15T14:09:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 15, 2016, 2:09pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/1 "2016-09-15T14:09:53Z")

</div>

Hi,

I’m new at Hugo, and I’m in the mid of porting all my site from wordpress to Hugo.  
Is there any ways to limit the words of summaries ?

As the default is first 70 words, how if I want to make it less than that ?  
The problem I faced right now is I the content from wordpress more tag is more than 70 words.

Cheers,  
Raff

---

<div class="post-metadata">

**Author:** ![digitalcraftsman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/digitalcraftsman/32/4142_2.png) [@digitalcraftsman](https://discourse.gohugo.io/u/digitalcraftsman)\
**Post date:** [September 15, 2016, 2:21pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/2 "2016-09-15T14:21:00Z")

</div>

Use `<!--more-->` in your content file. For more information look [here](https://gohugo.io/content/summaries/#user-defined-manual-summary-split).

---

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 15, 2016, 2:24pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/3 "2016-09-15T14:24:06Z")

</div>

Hi,

Thanks for your help, yes I already have `<!--more-->` tag from my previous exported wordpress post but the length are more than 70 words.

Seems like I didn’t have any ways to modify all my 1700 posts to make it short.

Cheers,  
Raff

---

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [September 15, 2016, 3:56pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/4 "2016-09-15T15:56:30Z")

</div>

Haven’t done this myself, but how about using the [string functions](http://gohugo.io/templates/functions/#strings)? It doesn’t seem possible to subtract the first 70 words from a string, but you can extract a certain amount of characters from the beginning of `.Content` it seems with `slicestr`.

---

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 15, 2016, 4:20pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/5 "2016-09-15T16:20:25Z")

</div>

Never tried this before, but lets see how far I can go with this.

Thanks for your help.

Cheers,  
Raff

---

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 15, 2016, 4:31pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/6 "2016-09-15T16:31:05Z")

</div>

**Update**

Okay, I managed to reduce the at least the text into 200 chars by:  
`{{slicestr .Summary 0 200}}`

So far I’m happy with the result for now.  
But let me know if you guys have another better approach to make excerpts.

Thanks for the help.

Cheers,  
Raff

---

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 16, 2016, 6:28am UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/7 "2016-09-16T06:28:31Z")

</div>

**Second update**

There is no issues on the display but I’ve got an error link this:  
`ERROR: 2016/09/16 14:26:32 template.go:131: template: theme/partials/blog.html:39:34: executing "theme/partials/blog.html" at <slicestr .Summary 3 ...>: error calling slicestr: slice bounds out of range in theme/partials/blog.html`

What would that be ?

While on the code:  
`<!--DETAILS--> <div class="content"> <ol class="breadcrumb"> {{ if isset .Params "categories" }} {{ if gt (len .Params.categories) 0 }} in <a href="{{ $.Site.BaseURL }}categories/{{ index .Params.categories 0 | urlize | lower }}">{{ index .Params.categories 0 }}</a></li> {{ end }} {{ end }} </ol> <h6><a href="{{ .Permalink }}">{{ .Title }}</a></h6> <p> {{slicestr .Summary 3 200}} </p> <a href="{{ .Permalink }}">Read More</a> </div>`

---

<div class="post-metadata">

**Author:** ![Jura](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jura/32/13581_2.png) [@Jura](https://discourse.gohugo.io/u/Jura)\
**Post date:** [September 16, 2016, 4:05pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/8 "2016-09-16T16:05:25Z")

</div>

> [@wsokc](#):
>
> There is no issues on the display but I’ve got an error link this:ERROR: 2016/09/16 14:26:32 template.go:131: template: theme/partials/blog.html:39:34: executing “theme/partials/blog.html” at \<slicestr .Summary 3 …\>: error calling slicestr: slice bounds out of range in theme/partials/blog.html
> 
> What would that be ?

Perhaps the `.Summary` of one of the posts was not 200 characters (an empty post), and with `slicestr` you tried to get the first 200 characters (which weren’t there).

If you check whether a post has a `.Summary` of at least 200 characters, does the error then go away?

For example (untested):

```
{{ if gt (len .Summary) 200 }}

  <h6><a href="{{ .Permalink }}">{{ .Title }}</a></h6>
  
  <p>{{slicestr .Summary 3 200}}</p>
  
  <a href="{{ .Permalink }}">Read More</a>

{{ end }}

```

---

<div class="post-metadata">

**Author:** ![wsokc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wsokc/32/2056_2.png) [@wsokc](https://discourse.gohugo.io/u/wsokc)\
**Post date:** [September 17, 2016, 4:16pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/9 "2016-09-17T16:16:06Z")

</div>

Works like a Charm,

Thanks a lot for your help, much appreciated.

Cheers,  
Raff

---

<div class="post-metadata">

**Author:** ![Hash\_Borgir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hash_borgir/32/6655_2.png) [@Hash\_Borgir](https://discourse.gohugo.io/u/Hash_Borgir)\
**Post date:** [March 19, 2017, 1:32pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/10 "2017-03-19T13:32:18Z")

</div>

You want to use this:

`{{slicestr .Summary 3 200 | markdownify }}`

Otherwise your summary show markdown code/formatting and won’t render it.

Cheers! 🙂

---

<div class="post-metadata">

**Author:** ![IsmaelG](https://avatars.discourse-cdn.com/v4/letter/i/74df32/32.png) [@IsmaelG](https://discourse.gohugo.io/u/IsmaelG)\
**Post date:** [February 26, 2018, 4:43pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/11 "2018-02-26T16:43:29Z")

</div>

Hi!  
Where should i put this?

Thanks!

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 26, 2018, 5:22pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/12 "2018-02-26T17:22:58Z")

</div>

You can set a new default:

```auto
summarylength = 30

```

Also there is a `truncate` template func that does what it says.

---

<div class="post-metadata">

**Author:** ![haoc7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/haoc7/32/6453_2.png) [@haoc7](https://discourse.gohugo.io/u/haoc7)\
**Post date:** [July 23, 2018, 4:17pm UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/13 "2018-07-23T16:17:54Z")

</div>

Hi,bep.  
I can set a new default:

```auto
summarylength = 10

```

However, it is invalid for Chinese.

---

<div class="post-metadata">

**Author:** ![yooxinz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yooxinz/32/6220_2.png) [@yooxinz](https://discourse.gohugo.io/u/yooxinz)\
**Post date:** [December 21, 2018, 6:41am UTC](https://discourse.gohugo.io/t/limit-the-summary/4103/14 "2018-12-21T06:41:12Z")

</div>

Use `hasCJKLanguage = true` solved it
