heimrichhannot/contao-likes-bundle

Put like/dislike buttons on anything in Contao CMS.

0.1.2 2025-06-17 16:17 UTC

This package is auto-updated.

Last update: 2025-06-17 16:18:20 UTC


README

Slap a like button on anything in Contao.

This Contao CMS bundle allows you to add like and dislike buttons to any (twig) template, liking or disliking whatever you please to your heart's content.

Features

  • Add like and dislike buttons to any template, attached to anything you want, e.g. models or your grandma's favorite knitting patterns
  • CSRF protection
  • Extensive base template included
  • Rate Limiting to prevent abuse
  • Session-less association of likes and dislikes to individual user-agents using a tiny anonymous fingerprint
  • Presumably GDPR-compliant, as no personal data is stored

Installation

You can install this bundle using Composer:

composer require heimrichhannot/contao-likes-bundle

Usage

To add a like button to your template, include a like & dislike button template and pass options as likes, preferably created by calling huh_likes() with a namespace and a target (these can be literally any strings you like to reference this likeable thing).

{{ include('@Contao/huh_likes/buttons.html.twig', { likes: huh_likes('knitting-pattern', 'honeycomb-lace') }) }}

On the Matter of liking Models

Most commonly, you will want to add a like button to something related to contao models, like a news article or a calendar event. In this case, we recommend using the model's table name as namespace and the model's ID as target. Or, even better, if you have access to the \Contao\Model instance directly in your template, just pass it in.

Table and ID Model Instance
huh_likes('tl_news', 42) huh_likes(model)

The Dislike Button and other Options

In the provided default template, the dislike button is NOT shown by default. If you want to show it, pass more options to the huh_likes() function:

huh_likes(model, null, {
    likes_enabled: true,
    dislikes_enabled: true,
})

Customization

Within the default template @Contao/huh_likes/buttons.html.twig, you will find four blocks that you can override with your custom icons:

  • icon_like_neutral
  • icon_like_set
  • icon_dislike_neutral
  • icon_dislike_set

With these blocks, you can easily replace the default icons with your own SVGs or any other HTML content.