comment¶
The comment
macro is used to render a single user comment on a page.
Definition¶
Input parameters¶
comment¶
BlogComment | ProductComment
BlogComment object | ProductComment object represents a single comment
options¶
object
represents an object of comments options
Option key | Type | Default | Required | Description |
---|---|---|---|---|
options.classNames | string |
"" | yes | additional classes that will be added to the comment element |
options.hasAvatar | boolean |
false | yes | if true displays avatar with authors first letter |
Example¶
Display comments for blog article with id 1.
{% from "@macros/comment.twig" import comment %}
{% set blogArticle = ObjectApi.getBlogArticle(1) %}
{% for comment in blogArticle.comments %}
{{
comment(comment, {
hasAvatar: true
})
}}
{% endfor %}
Macro source code¶
{% macro comment(comment, options) %}
{% set author = comment.author ?: comment.userName %}
<article class="comment {{ options.classNames }}">
<header class="comment__header">
{% if options.hasAvatar %}
<div class="comment__avatar hidden-xs-only">{{ author|first|capitalize }}</div>
{% endif %}
<div class="comment__header-details">
<p class="comment__author">{{ author }}</p>
<time
class="comment__date"
datetime="{{ comment.createdAt }}"
title="{{ comment.createdAt.dateLong }}"
>
{{ comment.createdAt.date }}
</time>
</div>
</header>
<p class="comment__content">{{ comment.content }}</p>
</article>
{% endmacro %}