truncate with inserted image

blindmime
@blindmime
11 years ago
772 posts
I have something like this to list blog posts:

{$row.blog_text|jrCore_format_string:$item.profile_quota_id|truncate:300}

There is an issue with this when a post contains an inserted image at the beginning. I think it just stops outputting the rest of the template where this resides and at that point, and then continues outputting the rest of the page.

For example, I have the above in index_list_blogs.tpl, in an altered Elastic skin. I'm listing 5 recent blogs in the center column of index.tpl. The list of blogs is the last thing in that column. I have a blog post with an inserted image at the beginning of the post. It outputs the image, but nothing else. The last column is output, but the closing divs in the center column are missing so the last column is output down below the container.

I think you should be able to test this in jrElastic since I haven't altered much besides moving blocks around. Probably you understand what's going on without needing to test it. I'm guessing the image is stored as a blob so the truncate length includes the blob, but something happens when truncating in the middle of that.

Maybe there is already something in jrCore_list which accounts for this. I'm not sure what the best way would be, but I think I would like to include the inserted image in this particular blog list, however, I can also see where you might want the option to not include inserted images in a jrCore_list listing as well.
updated by @blindmime: 09/19/14 05:17:25AM
douglas
@douglas
11 years ago
2,806 posts
I've seen this too and I think the truncate counts the code for the image, ie.

<img src="... etc.

gets counted as characters and it is probably truncating correctly. Can you move the image further down in the blog?



--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos

updated by @douglas: 08/18/14 07:17:15AM
blindmime
@blindmime
11 years ago
772 posts
300 characters truncated was producing this error with an image at the beginning, throwing the page off. I generally like an image at the beginning of a post and this error occurs also if you put the image in the blog_image field. I could move the image down, of course, but other users will not know that this should be done.


updated by @blindmime: 08/18/14 12:51:46PM
brian
@brian
11 years ago
10,149 posts
Change it to this:

{$row.blog_text|jrCore_format_string:$item.profile_quota_id|strip_tags|truncate:300}

any time you are truncating I would strip the HTML tags before the truncate.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
blindmime
@blindmime
11 years ago
772 posts
Won't this strip out the photo? Many blog indexes have a list of recent blogs which consist of a picture then some text and then a link to read more. That's what I'm trying for.
michael
@michael
11 years ago
7,806 posts
If you want to force an image, then use the form designer (if there isnt a blog_image there already ) to add a blog_image.

Put that blog_image at the top, then the text.

Or you could use the read-more button instead of truncate.
{$row.blog_text|jrBlog_readmore

Tags