Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the "Read More" text for a post preview when using post.preview instead of post.get_preview in Timber?

Before Timber version 1.3.1, if you wanted to change the Read More text for a post preview, you could use {{ post.get_preview(50, 'false', 'Keep Reading') }}. This function has been deprecated and it is recommended to use {{ post.preview }}, but it doesn't seem to have the ability to filter the Read More text easily.

like image 260
Wes Cole Avatar asked Jul 27 '17 14:07

Wes Cole


1 Answers

It doesn’t seem easy, probably because it isn’t documented yet. But we’re working on it!

{{ post.preview }} returns a PostPreview object, which is a chainable object. This means that you can change the output of the preview by adding methods.

In your example, when you want to change the read-more text:

{{ post.preview.read_more('More!') }}

If you’d also want to change the length to 10 words only, you could do something like this:

{{ post.preview.length(10).read_more('More!') }}
like image 76
Gchtr Avatar answered Nov 14 '22 16:11

Gchtr