Hi there,
Is there an easy(ish) way I can pass a variable in to the Commentions plugin form template so that I can change the heading based on which page it’s in?
i.e. something like instead of ‘Leave a comment’, ‘Have some thoughts about [page title]?’
Any help much appreciated,
Thanks,
Rach
(@sebastiangreger)
Hi,
Thanks for the brain teaser!
Since that particular text is displayed using the I18n engine – <?= t('commentions.snippet.form.ctacomment') ?>
in snippets/commentions_form.php
– I can’t see how that could be achieved using the “easiest” way, i.e. by integrating the page title in the translation string (custom translation strings in config.php
do not have access to the $page
or page()
object).
So, the only way I can see with the current stable version of Commentions is to copy the file site/plugins/kirby3-commentions/snippets/commentions_form.php
to site/snippets/commentions_form.php
(“Create your own frontend presentation”) and edit at heart’s content. You could replace all instances of <?= t('commentions.snippet.form.ctacomment') ?>
with <?= 'Have some thoughts about' . $page->title() ?>
to achieve your desired outcome.
While this is actually “easy” as well, the downside is that this may require manual work whenever you update the Commentions plugin later (as the built-in snippets, and the form snippet in particular, are closely tied to the logic of the plugin and may change; as a matter of fact, version 2 of Commentions is currently in late beta and will come with entirely renewed snippets).
I created an issue about this thread as a reminder; the feature you are after might actually be very easy to add to v2.0 of the plugin; this use case simply never popped up before. In case you are working on a fresh website project, I’d almost dare you to use that branch anyways (even though development has slowed down a bit the past few weeks).
Update: This is now possible in today’s Commentions v2.0-beta.3 release.
Documented in the Readme, I believe this would do what you were after when you call the commentions()
helper in your template:
<?= commentions('form', [
't' => [
'en' => [
'ctacomment' => 'Have some thoughts about "' . $page->title() . '"?',
],
]
]) ?>
All feedback and/or bug reports most welcome