grav-plugin-comments/templates/partials/comments.html.twig

115 lines
4.7 KiB
Twig

{% if grav.twig.enable_comments_plugin %}
{% set scope = scope ?: 'data.' %}
{% if grav.twig.pingbacks_enabled %}
{% if grav.twig.pingbacks|length %}
{% set comments_visible = false %}
{% for pingback in grav.twig.pingbacks %}
{% if pingback.approved == "true" %}
{% set comments_visible = true %}
{% endif %}
{% endfor %}
{% if comments_visible %}
<h3>{{'PLUGIN_COMMENTS.COMMENTS_PINGBACKS'|t}}</h3>
<table>
{% for pingback in grav.twig.pingbacks %}
{% if pingback.approved == "true" %}
<tr>
<td>
{{pingback.text}}
<br />
{{'PLUGIN_COMMENTS.WRITTEN_ON'|t}} {{pingback.date|e}} {{'PLUGIN_COMMENTS.BY'|t}}
{% if pingback.site %}
<a href="{{pingback.site}}">{{pingback.author}}</a>
{% else %}
{{pingback.author}}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</table
{% endif %}
</table>
{% endif %}
{% endif %}
{% if grav.twig.commenting_enabled %}
<h3>{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}</h3>
<form name="{{ grav.config.plugins.comments.form.name }}"
action="{{ grav.config.plugins.comments.form.action ? base_url ~ grav.config.plugins.comments.form.action : page.url }}"
method="{{ grav.config.plugins.comments.form.method|upper|default('POST') }}">
{% for field in grav.config.plugins.comments.form.fields %}
{% set value = form.value(field.name) %}
{% if field.evaluateDefault %}
{% set value = evaluate(field.evaluateDefault) %}
{% endif %}
{% if config.plugins.login.enabled and grav.user.authenticated %}
{% if field.name == 'name' %}
<input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.fullname}}">
{% elseif field.name == 'email' %}
<input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.email}}">
{% else %}
<div>
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
</div>
{% endif %}
{% else %}
<div>
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
</div>
{% endif %}
{% endfor %}
{% include "forms/fields/formname/formname.html.twig" %}
<div class="buttons">
{% for button in grav.config.plugins.comments.form.buttons %}
<button class="button" type="{{ button.type|default('submit') }}">{{ button.value|t|default('Submit') }}</button>
{% endfor %}
</div>
{{ nonce_field('form', 'form-nonce')|raw }}
</form>
<div class="alert">{{ form.message }}</div>
{% endif %}
{% if grav.twig.comments|length %}
<h3>{{'PLUGIN_COMMENTS.COMMENTS'|t}}</h3>
<table>
{% set comments_visible = false %}
{% for comment in grav.twig.comments %}
{% if comment.approved == "true" %}
{% set comments_visible = true %}
<tr>
<td>
{{comment.text}}
<br />
{{'PLUGIN_COMMENTS.WRITTEN_ON'|t}} {{comment.date|e}} {{'PLUGIN_COMMENTS.BY'|t}}
{% if comment.site %}
<a href="{{comment.site}}">{{comment.author}}</a>
{% else %}
{{comment.author}}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% if not comments_visible %}
<tr>
<td>
{{'PLUGIN_COMMENTS.COMMENTS_NONE'|t}}
</td>
</tr>
{% endif %}
</table>
{% endif %}
{% endif %}