I am trying to customize the html rendered for the blogPosts (post list) page (in my theme this is using the blog.htm template).
From here: {octobercms url, this talk thing wont let me use url!}/plugin/rainlab-blog > Documentation:
The post list and the pagination are coded in the default component partial plugins/rainlab/blog/components/posts/default.htm
. If the default markup is not suitable for your website, feel free to copy it from the default partial and replace the {% component %}
call in the example above with the partial contents.
When I do the above, I get a blank page.
It seems that ‘posts’ is not being populated properly, since when I use the simplified code below in my blog.htm:
title = "Blog"
url = "/blog/:page?"
layout = "default"
meta_title = "Blog"
meta_description = "Desc"
[blogPosts]
postsPerPage = "5"
==
<!--{% component 'blogPosts' %}--> <!-- this works fine -->
<!-- todo: use partial blog/list.htm -->
{% set posts = __SELF__.posts %}
post count:
{{ posts|length }}
I get output:
post count: 0
Any help much appreciated!
1 Like
in backend editor, you can darag in component, and then right click, Expand Component partial,
If manualy, you copy, you need to replace all ___SELF___
with comoponent name like in my screenshot it would be
{% set posts = ArticleList2.posts %}
1 Like
I recommend overriding the component partials, like shown in the docs here: Components - October CMS - 3.x
This gives you a lot of flexibility and doesn’t clutter your pages with markup.
In the partials directory of your theme, you can either create a folder with the same name as the alias of your component, to override the markup for a specific component placement, or create a folder with the component name to override the default markup for all placements of that component.
for example:
title = "Blog"
url = "/blog/:page?"
layout = "default"
meta_title = "Blog"
meta_description = "Desc"
[blogPosts mainblog]
postsPerPage = "5"
==
would be overridden by markup in the folder [theme]/partials/mainblog/default.htm
If a component has multiple partials, you can also just override a single file.
In there you can use everything that is available to the component and also reference the component with SELF.
1 Like
Thanks so much guys, both answers work.
@marco.grueter thanks, this is quite an elegant solution (new concept learnt! every day’s a schoolday right ), have used this.
For blog listing (default override) using:
[blogPosts blog]
postsPerPage = "5"
==
{% component 'blog::list' %}
(and for category.htm, using pretty much exactly the same, as they both use the same partial - to list blog posts)
@marco.grueter
Ouh, this is really nice, did not know. Thanks!