Blog

20 views
Skip to first unread message

Cli F

unread,
Sep 14, 2016, 1:23:16 AM9/14/16
to apostrophenow
Hi there, we've set up the blog. A couple of queries...

1. Curious about how to truncate post data to display a list of snippets (like your demo)

Pre this new release, the way to display them was to use {{ aposAreaPlaintext(piece, 'body', { truncate: 200 }) }}

I can produce content from the snippet using a slightly altered version of this, but it wont' truncate the data:

{{ aposAreaPlaintext(piece, 'body', { truncate: 200 }) }}

2. Is pagination built into the module?

3. I can add tags, but how do we display those tags. Also I am assuming category support is something for us to code in.

Tom Boutell

unread,
Sep 16, 2016, 11:01:59 AM9/16/16
to apostr...@googlegroups.com
Hi,

1. A new equivalent of aposAreaPlaintext is forthcoming. We need it
too, of course.

2. Pagination is built into the module for sure. Anything that
subclasses apostrophe-pieces-pages gets pagination "for free."

However I see that the pager is missing from the default index.html,
which is confusing for sure! I just published an update that includes
the pager in index.html. You'll be overriding it but it clearly ought
to demonstrate this feature.

3. As for displaying tags, you have access to them as the .tags array
on individual blog posts. In addition, consider this code from the
index.js of one of our project-level uses of the blog module:

module.exports = {
construct: function(self, options) {
var superBeforeIndex = self.beforeIndex;
self.beforeIndex = function(req, callback) {
return superBeforeIndex(req, function(err) {
if (err) {
return callback(err);
}
// use async.series, in case we get more stuff later
return async.series([
// get all tags
function(callback) {
self.pieces.find(req, {}).toDistinct('tags', function(err, tags) {
if (err) {
return callback(err);
}
req.data.allTags = tags || [];
return callback(null);
});
}
], function(callback);
});
};
}
};

Now you can use data.allTags in your template.

See also:

http://apostrophenow.org/tutorials/intermediate/cursors.html
> --
> You received this message because you are subscribed to the Google Groups
> "apostrophenow" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to apostropheno...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com

Tom Boutell

unread,
Sep 16, 2016, 11:02:29 AM9/16/16
to apostr...@googlegroups.com
(There is already a "tag" cursor filter out of the box, so if you put
a tag in the query string of the index page, it'll filter on that.)

Cli F

unread,
Sep 18, 2016, 10:20:21 PM9/18/16
to apostrophenow
The new apos.areas.plaintext in 2.1.1 works well, except that it doesn't seem to truncate pieces. So we still cannot create blog snippets. I So this will show the article, but won't truncate it:

{{ apos.areas.plaintext(piece, 'body', { limit: 20 }) }}

I have also tried a variation on your code, but it doesn't produce any data:

{{ apos.areas.plaintext(data.piece.body, { limit: 20 }) }} 

Tom Boutell

unread,
Sep 18, 2016, 10:54:06 PM9/18/16
to apostr...@googlegroups.com
Looking at what you wrote, my educated guess is that you're trying to
do this in a macro or in a loop inside index.html where "piece" is a
variable, so "data.piece" is not apropos the way it would be in, say,
show.html.

So my syntax is right, you just need to account for the variable you
actually have as a starting point.

{{ apos.areas.plaintext(piece.body, { limit: 20 }) }}

Your other syntax worked because plaintext is smart enough to search
the entire piece for areas if you don't specifically give it the body.
And since the second argument was a string rather than an options
object, it was completely ignored, which is why you got no truncation.

Cli F

unread,
Sep 19, 2016, 1:11:39 AM9/19/16
to apostrophenow
That's spot on, thank you
Reply all
Reply to author
Forward
0 new messages