Forum Discussion
Thank you for this excellent documentation and code sample for displaying the latest three blog entries from the community in a custom component.
I have taken this and added it to our community and it is working well, however I would like to make it display like the Lithosphere version, which includes a teaser image on the left, then the title and teaser in the middle and all the way to the right is the friendly date, the author name and a tiny thumbnail of the author.
Here is a snapshot of the Lithosphere recent blog articles captured from the home page of the community today. What I would like to know is where to the teaser images come from? Are they coming from a special location, or are they simply included in the teaser of the blog by policy?
I would also like to know where to get the tiny thumbnails for the author are found. Are they standard or custom?
Thanks again for the great post.
- MoniqueL12 years agoLithium Alumni (Retired)
"What I would like to know is where to the teaser images come from?"
For that particular component, some free marker has been added to pull in an image if an image has been added to the blog teaser section when a blog author is drafting their article. If the author fails to add a custom image specific to that blog teaser/article, then it'll pull in the "generic" Li image"
Also note that some css has been added to force the blog teaser images in this component to be the same square size as the li image, for a more uniform look. I would suggest tweaking the css or simply not relying on the css but rather try to have your creative team and/or blog authors crop & create images for blog teasers that are a consistent in size & ratio so you avoid image distortion that you sometimes see on the lithosphere
<td class="image<#if thisRow == 3> last</#if>"> <#assign teaser = message.teaser /> <#assign imageLink = " " /> <#assign imgPosB = teaser?index_of("<IMG src=") /> <#if (imgPosB > 0) > <#assign teaser2 = teaser?substring(imgPosB) /> <#assign imgPosE = teaser2?index_of("/>") /> <#if (imgPosE >0) > <#assign imageLink = teaser2?substring(0, imgPosE) + " height=110px width=110px /> " /> <#assign teaser = teaser?substring(0, imgPosB) + teaser2?substring(imgPosE+2) /> </#if> </#if> <div style="width: 110px; height: 110px; background-image: url('/html/assets/blogfeedimgsquare-blue.png'); border-radius: 2px;"> ${imageLink} </div> </td>
"I would also like to know where to get the tiny thumbnails for the author are found. Are they standard or custom?"
They're standard in the sense that the particular freemaker code here is reference the message size version of the avatar but relying on specifically written css for this component to shrink the image down.
<td class="created<#if thisRow == 3> last</#if>">
<div id="date"><#if (useFriendlyDate) >${message.post_time.@view_friendly_date}<#else>${message.post_time.@view_date?date("MM-dd-yyyy")}</#if></div>
<#assign avatar = rest(message.author.@href + "/profiles/avatar/size/message").image>
<div id="authors"><a href="${message.author.@view_href}">${message.author.login}</a> <a href="${message.author.@view_href}"><img src="${avatar.url}" title="${message.author.login}" /></a></div>
</td- ebroyles12 years agoMaven
Thank you very much, MoniqueL, for answering my questions directly and providing the exact code to do what I wanted. I have implemented that in my custom component and it works just as claimed.
Before you responded, I had come up with my own solution which is slightly different, and I will share with the community in case it may be of value to anyone. Not knowing how to include an image in the teaser but be able to yank it out and display it elsewhere (which is effectively what MoniqueL's solution does), I made use of the REST API and the fact that a message has an images collection.
Here is the relevant portion of the code.
<td class="image"> <#assign images_for_message = rest("${message.@href}/images").images /> <div style="width: 110px; height: 110px; margin: 0px 10px 10px 0px; background-image: url('/html/assets/community-blog-teaser-background-110.jpg'); border-radius: 2px;"> <#if images_for_message?size gt 0> <#list images_for_message.image as image> <img src="${image.thumbnail.url}" alt="${image.title}" title="${image.title}" border="0" align="left" width="110px" height="110px"/> <#break> </#list> </#if> </div> </td>
This calls the REST API to get a list of the images for the message and then loops through them (if any exist) and displays the thumbnail version of the first one it finds, ignoring all the others. It carries the same caveat that MoniqueL's code carries with respect to the sizing of images, though it specifically sizes the image right here in the code rather than relying on separate CSS styles.
MoniqueL's code has the advantage of enabling the author to decide which image to include in the teaser and also choose an appropriate size, and for that reason I prefer it over my original solution.
- MoniqueL12 years agoLithium Alumni (Retired)
Kudos ebroyles on the creative solution :) My apologies for not being able to post a code example sooner! But as you said, hoping that someone else out there finds this useful.
- jc75811 years agoAdvisor
Hi
We're trying to do almost the same... but i was wondering if there is an rest api method to retreive images from the blog teaser. There is an api call for the images contained in a blog message (example: http://community.lithium.com/restapi/vc/messages/id/128039/images ), but i can't found the teaser's images.
In the example you provide, we need to manually parse the teaser string, which is quite tedious and having it in a rest call would simplify the customisation on a blog page...
regards
JC
- PaoloT11 years agoLithium Alumni (Retired)
Hi jc758
The images are normally included as a part of the teaser body. Therefore it's not possible to expose a rest call, simply because the teaser can really be anything - it's a text field that the user can populate with arbitrary HTML markup and it's not safe to assume that a teaser image will always be present in your code.
A potential improvement would be to include the image parsing logic in a Macro - so that you can define it once in the Endpoints section in Studio and maintain it in one place, then simply use the macro on the teaser content in your components which would greatly clean up your logic.
Hope this helps,
Related Content
- 5 years ago
- 13 years agoInactive User