Timber: post.preview doesn't work if not ending with </p> tag

Created on 11 Nov 2019  路  5Comments  路  Source: timber/timber

Expected behavior

Get all the preview that I've defined in the Post.

Actual behavior

If I define a More Tag right after an element like a <ul> or <img> the post preview will only show my last <p> element and will ignore all later elements.

So I'm forced to write all tags:
{{ post.preview.read_more(false).strip('<div><p><ul><ol><li><a><img>') }}

Steps to reproduce behavior

  1. Create a WordPress post and write something with this structure:
<p></p>
<p></p>
<ul></ul>
<!--more  -->
<p></p>

{{ post.preview.read_more(false).strip(false) }}

After some testing the problem seems to be on this line:
https://github.com/timber/timber/blob/2cdb07fdd2baa05907d5457f4e621549540f427e/lib/PostPreview.php#L229

help wanted

Most helpful comment

@claudiopedrom yes you're right about where is the problem.

I think that now, when many of us is using the Gutenberg editor the chance when we'll end the text in more with something else than </p> are much greater than before so this rules may only cause more trouble.

I think that, for keeping everything backward compatible we should:

  • by default leave this exactly how it's working
  • add some extra variable to the if if ( !$this->strip && !$this->new_behaviour ) {
  • create a filter for the new variable so by default it will be false but if someone would prefer to change it true
  • be new behaviour I think that the user should responsible where they put the <!--more--> tag.
  • at some point - remove this part of code

All 5 comments

Same issue here.

@claudiopedrom yes you're right about where is the problem.

I think that now, when many of us is using the Gutenberg editor the chance when we'll end the text in more with something else than </p> are much greater than before so this rules may only cause more trouble.

I think that, for keeping everything backward compatible we should:

  • by default leave this exactly how it's working
  • add some extra variable to the if if ( !$this->strip && !$this->new_behaviour ) {
  • create a filter for the new variable so by default it will be false but if someone would prefer to change it true
  • be new behaviour I think that the user should responsible where they put the <!--more--> tag.
  • at some point - remove this part of code

@claudiopedrom @rgllm thanks for the tip and the very very helpful full description.

@palmiak does a great job of laying out steps to resolve. Given the likely change for existing behavior, I'd suggest just PR'ing this into 2.0 so we can jettison legacy support. Anyone want to claim?

@jarednova so you think we should leave version 1.x as it is and prepare just for 2.0 or prepare both versions for 1.x with legacy support and 2.x without?

I'd say let's _start_ with 2.x (without legacy support). Once there, we can port that into 1.x and add in legacy support!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bambamboole picture bambamboole  路  6Comments

sgu1 picture sgu1  路  3Comments

petenorris picture petenorris  路  4Comments

chetzof picture chetzof  路  4Comments

jarednova picture jarednova  路  5Comments