Reputation: 807
At the time I ran into a problem when creating a component for my plugin in octobercms. The problem is when I run the following query:
public function onRender(){
$blogs = BlogPost::where('published', 1)
->where('published_at', '<=', 'NOW()')
->orderBy($this->property('sortOrderBy'), $this->property('sortOrder'))
->with('tags')
->paginate($this->property('postsPerPage'));
$this->blogs = $blogs;
//print_r($blogs);
}
But if I want to display a result of tags that belong to the post in the html of the component with {{}} post. Tags come json output. How can I make sure that I can show the names of the tags?
My component file:
{% for post in posts.blogs %}
<p>{{ post.titel }}</p>
<p>tags: {{ post.tags }}</p>
{% endfor %}
Upvotes: 1
Views: 1172
Reputation: 846
post.tags is a collection of tag. More info about collections https://octobercms.com/docs/database/collection
Try this code to browse the tags collection :
{% for post in posts.blogs %}
<p>{{ post.titel }}</p>
<p>tags:
{% for tag in post.tags %}
{{ tag }}
{% endfor %}
</p>
{% endfor %}
{% endfor %}
Could be also {{ tag.name }} or {{ tag.title }} instead of {{ tag }}
Upvotes: 1