Post Excerpt With HTML Content

Is there a way to add a html tags like <a href""> as part of the Excerpt content?


You might be able to use
{{content words="100"}}
Which should get you the first bit of your content with html.

and where should this be added?


Ah to be fair I was assuming you were editing your handlebars theme. If you’re not then Im not certain it’s possible to add html to the current custom excerpt field.

If you are you’d just swap out where you have {{excerpt}} for {{content words=“100”}} in the template file that you want to show it in.

Ok I just tried swapping

{{excerpt words=“100”}}


{{content words=“100”}}

in partials/post-card.hbs file. It seems to completely remove the content and just show the title…

This is the section:

{{#if feature_image}}

{{excerpt words=“30”}}


{{excerpt words=“100”}}


So to be super clear to make sure we’re on the same page, when you use the content helper it’s going to be showing the first 100 words of the main content of your post and not whatever you may have typed up into the box labeled excerpt for the post.

That said you may want to backspace and handtype {{content words="100"}} into your editor, because when I tried copying it just now it didn’t work right either because some of the characters copied over in a way that didn’t parse correctly even though it looked fine at a glance. (I got some different type of quotation mark that was curved rather than straight and that apparently was enough to throw it off).

Thanks for the detailed writeup.

You are right. {{content words=“100”}} seems to print just empty line even though I have hand typed content in the post body. I am still trying to figure out a workaround to handle html content especially a url with tag in excerpt section.

Instead of using the Excerpt field you might want to use one of the code injection areas, that way you can apply completely custom HTML for the excerpt. Note that you will need to customise your theme to repurpose the code injection field

@DavidDarnes is {{ghost_head}} for a specific post accessible from its object when using something like {{get ‘posts’}}?

Sorry I’m not sure what you’re asking, could you rephrase the question? :slight_smile:

If I have code like this:
{{get ‘posts’}}
{{#foreach posts}}
< div>{{ghost_head}}<\div>

In home.hbs (whose context is a page I’m replacing index with), should I be getting the code injection block for each post output in a div or will I just get the home pages code injection block instead?

Also a completely different question, the formatted for code segments in this part of the forum is terrible. Why is different from the other ones?

So I was messing around in ghost trying to figure out various ways to access the different properties for a post and I found a way for you to put html in your excerpt and have it output the way you expect!

Wherever you want your excerpt with the html in it to show for the post you’ll want to put this: {{{custom_excerpt}}}

“custom_excerpt” is where the text you added as your excerpt, gets stored before Ghost’s builtin helpers do anything with it, and the triple brackets tells handlebars that you don’t want it to sanitize the html tags present in the field.


Wow! that’s a lot of messing around :slight_smile:

Thanks for the tweak. I will give it a try.

@sunlanterns I hearted this for awesomeness, but I wanted to give this 10 hearts.

Since we are allowed only one heart per post, I am adding the additional 9 more here: :purple_heart: :blue_heart: :green_heart: :yellow_heart: :orange_heart: :heart: :brown_heart: :black_heart: :white_heart:

1 Like