timber
timber copied to clipboard
post.preview doesn't work if not ending with </p> tag
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
- 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
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 ittrue
- 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!
Added the 2.x tag for good measure.