[英]How to render json output in Octobercms component
At the time I ran into a problem when creating a component for my plugin in octobercms. 当时我在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. 但是,如果我想使用{{}} post在组件的html中显示属于post的标签的结果。 Tags come json output.
标签来自json输出。 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 %}
post.tags is a collection of tag. post.tags是标签的集合。 More info about collections https://octobercms.com/docs/database/collection
有关集合的更多信息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 }} 也可以是{{tag.name}}或{{tag.title}}而不是{{tag}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.