Show preview / summary of article
AnsweredHi Community,
Just wondering: is it possible to pick up part of an article (via API)? E.g. a paragraph / anchor. Use case is that we want to show a short summary of an article in our own web-application. Most convenient would be that our authors can write this summary directly in the article within ZD Guide and we are able to pick up that particular piece of text via API.
Anybody have any ideas or tips? Of maybe a similar use case?
Many thanks!
Ron
-
Hi @Ron de Vries,
As long as your article or HC is public, I think it's quite possible to do so. You can simply add an id or class to the paragraph then using API you can get the article body. From that, you can choose the <p> element and use it.
Thanks
-
Hi @...,
Thanks! I actually have some JQuery that adds a css class when <p> contains a specific word or phrase (see below). Using API it would be possible to pick up this class and the body of the <div> class blockquote-important in your opinion? Is there any documentation on this as far as you know?
Cheers!
$(document).ready(function() {
// add css class
$("p:contains('Important:')").addClass('blockquote-important'); -
@...,
I am not sure about the documentation but here I wrote a code roughly to achieve what you want. Try giving it a shot.
$.get(ARTICLE_API, function(data) { // Replace ARTICLE_API with you article api url
var articleBody = data.article.body;
var parser = new DOMParser();
var doc = parser.parseFromString(articleBody, 'text/html');
console.log( $(doc).find('.blockquote-important').html() );
});Thanks
-
Hi @...,
Many thanks! We'll try and get this working using your examples as well. I will conduct with our Developer. If we get it working I will update this post.
Have a great day!
Please sign in to leave a comment.
4 Comments