Show excerpt for all topics via a theme

(Joe) #1

Continuing the discussion from Show "topic-excerpt" for all post on Latest Page:

I am interested in showing an excerpt for all topics. The linked topic above covers the subject very well. And @angus left a very helpful reply describing how to achieve what I’m after.

However, this is all under plugin structure.

My question is, is it possible to turn on or enable excerpts for all posts via a theme? In other words, I would like to change:


def include_excerpt?

via a theme component.

I know that @sam mentioned this:

But figured I should ask in case things have changed since. My use case is a modified topic list template that looks like this:

Notice how only a pinned topic would show an excerpt while I’d like all of them to do that.

Show "topic-excerpt" for all post on Latest Page
(Angus McLeod) #2

It’s not possible via a theme. But you could just make a simple plugin that does this.


# name: post-excerpts
# about: All posts have excerpts
# version: 0.1
# authors: Huckleberry Finn

after_initialize do
  add_to_serializer(:listable_topic, :include_excerpt?) { true }

That’s the whole plugin (untested, but it should work).

(Carlo) #3

Hi Angus.
I’d like to add excerpt in the default json feed of discourse ( latest and top ), for each topics.

Can this plugin do the job ? Sorry if my question sounds dumb :roll_eyes:

(Angus McLeod) #4

Yup, those 3 lines should be enough to add excerpts to those json endpoints.

(Joe) #5

Amazing as always @angus!

Thank you so much for the detailed answer :grin:

If it really only comes down to a plugin, then me proceeding with this would be pointless as the Topic List Previews plugin does a much better job and with a lot more configurable settings.

My hope was to create a theme component that modifies the topic list to show a thumbnail and an excerpt for all posts - applies to all categories.

I got everything ready except the excerpt.

(Angus McLeod) #6

Well, maybe not pointless. The TLP plugin is big and a bit unwieldy. A theme + a 3 line plugin, may be a more lightweight solution to the specific problem you’re trying to solve.

(Joe) #7

Of course, you’re right. :sunflower:

It’s just that I was hoping to fit in that small gap where you just want show a preview for all topics without requiring a plugin.

The only reason I lean towards a theme here is ease of access and not performance. I use the TLP and performance was never an issue :wine_glass:


I followed your advice and packaged it as a plugin.

In case anyone is interested:

Does it work? You bet :grin:

I’d be happy to release the cleaned up - still not finished - template as a standalone theme if this ever becomes possible.

Possible to have "Card" View for Discourse?
(Carlo) #8

You’re my hero! Thanks! I also confirm it works 100%

(magoz) #9

That’s awesome, thanks!!
My only issue is that is no longer possible to control the excerpt length via Settings > post excerpt maxlength. Changing the value has no effect anymore.

Or, at least, it’s not working for me.

Does it work for you @Johani? :thinking:

(Joe) #10

Yeah, I remember running into this as well.

(I’m going from memory here)

The setting still works but you need to rebake the posts to see the changes.

Something like this:

If that doesn’t work, let me know and I will look further.

(magoz) #11

I’ve tried using:

I also rebuilt the app.
But no luck, it doesn’t work.

To display the excerpts I’m using this script in the </head:

<script type='text/x-handlebars' data-template-name='list/topic-list-item.raw'>
  (more code)

  {{#if topic.hasExcerpt}}
    <div class="topic-excerpt">
       {{{dir-span topic.escapedExcerpt}}}

  (more code)

Thanks for your help @Johani!

(magoz) #12

As a temporary solution, I’m limiting the height of the excerpt in a way that only shows two lines.
Not ideal, but works more or less okay.

Here is the css code, in case someone else is facing the same issue:

.topic-list .topic-excerpt {
    height: 3.4rem;
    overflow: hidden;

(Carlo) #13


I had another question. It is possible to use the last reply as excerpt ?
Because I am using the Json feed to display the last reply on my website.


(jjaarrvviiss) #14

Love this theme, and love the card layout.

I tried installing Vincent theme but I couldn’t get the card layout to work.

Is the template in the screenshot available to use?

(Daniela) #15

Please read the topic carefully

You need to install a plugin

Maybe @Carlo and @magoz can share a link to their respective sites (if they are public) so you can see a live example

(jjaarrvviiss) #16

Thanks for the help.

Yes, I tried installing @Johani’s plugin but I believe it needs to work in connection with a theme/template that they have created? I believe the template is displayed in the screenshot in this post:

I couldn’t get just Vincent plus the plugin to work so I assumed it was needing an extra template.

(jjaarrvviiss) #17

@Johani is this theme/template available to use? Thanks!!

[ARCHIVE] Topic List Previews
(Joe) #18

I stopped working on this a long time ago due to performance issues since I was getting 8mb pages due to using default topic thumbnails, so no it’s not available for use. You need a plugin to generate smaller thumbnails.

However, if you insist, here’s where I stopped - presented as is with no promises and no support.

ember.dcstyle.json (15.0 KB)

This is a theme file, so just download to your computer and import it as a theme.

This is far, far from ready to be used but it’s a start.

(jjaarrvviiss) #19

Wow thank you so much! I appreciate you sharing your work. have a great day

(Erlend Sogge Heggen) #20

@team would we accept a PR to enable excerpts in the #plugin:voting plugin? Would like to try out an alternative style for it with a theme component.