PHPackages                             knplabs/knp-disqus-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. knplabs/knp-disqus-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

knplabs/knp-disqus-bundle
=========================

v4.1.0(4y ago)6480.8k↑150%18[3 issues](https://github.com/KnpLabs/KnpDisqusBundle/issues)[3 PRs](https://github.com/KnpLabs/KnpDisqusBundle/pulls)MITPHPPHP &gt;=7.2.5

Since Nov 27Pushed 3y ago27 watchersCompare

[ Source](https://github.com/KnpLabs/KnpDisqusBundle)[ Packagist](https://packagist.org/packages/knplabs/knp-disqus-bundle)[ Docs](http://github.com/KnpLabs/KnpDisqusBundle)[ RSS](/packages/knplabs-knp-disqus-bundle/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (0)

KnpDisqusBundle
===============

[](#knpdisqusbundle)

If you use [Disqus](https://disqus.com) on your website for comments the comments are loaded dynamically via JavaScript, which could negatively impact SEO.

This bundle will fetch the comments using Disqus API so that you can include them on your page… before replacing the comment `div` by the Disqus JavaScript widget.

This way you benefit from both the JavaScript widget and the robot-friendly comments.

[![Build Status](https://camo.githubusercontent.com/73566e7c1171b3f894a6803935e01e125330d8a4b2e74f354aa324ba6ba8eed1/68747470733a2f2f7472617669732d63692e6f72672f4b6e704c6162732f4b6e7044697371757342756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/KnpLabs/KnpDisqusBundle)

[![knpbundles.com](https://camo.githubusercontent.com/91cf4c2d62b84c272741167400ae0735a59253835b7591bf98bc0cec48e23cbe/687474703a2f2f6b6e7062756e646c65732e636f6d2f4b6e704c6162732f4b6e7044697371757342756e646c652f62616467652d73686f7274)](http://knpbundles.com/KnpLabs/KnpDisqusBundle)

Requirements
------------

[](#requirements)

- Disqus API: [public key](http://disqus.com/api/applications/register/)

Installation
------------

[](#installation)

With [composer](http://packagist.org), run:

```
composer require knplabs/knp-disqus-bundle

```

If you're not using Symfony Flex, then you will also need to enable `Knp\Bundle\DisqusBundle\KnpDisqusBundle` in your `bundles.php` file.

Next, create a `config/packages/knp_disqus.yaml` file:

```
# config/packages/knp_disqus.yaml
knp_disqus:
    api_key: '%env(DISQUS_API_KEY)%'
```

And finally, configure the `DISQUS_API_KEY` in your `.env` or `.env.local` file:

```
# .env

DISQUS_API_KEY=ABC123

```

Usage:
------

[](#usage)

### In your Twig template:

[](#in-your-twig-template)

```
{{ knp_disqus_render('your_disqus_shortname', {'identifier': '/december-2010/the-best-day-of-my-life/', 'limit': 10}) }}
```

You can also show comments for specific language:

```
{{ knp_disqus_render('your_disqus_shortname', {'identifier': '/december-2010/the-best-day-of-my-life/', 'language': 'de_formal'}) }}
```

### Or in Controller:

[](#or-in-controller)

```
use Knp\Bundle\DisqusBundle\Client\DisqusClientInterface;

public function somePage(DisqusClientInterface $disqusClient)
{
    // ...

    $comments = $disqusClient->fetch('your_disqus_shortname', [
        'identifier' => '/december-2010/the-best-day-of-my-life/',
        'limit'      => 10, // Default limit is set to max. value for Disqus (100 entries)
    //    'language'   => 'de_formal', // You can fetch comments only for specific language
    ]);

    return $this->render('articles/somePage.html.twig', [
        'comments' => $comments,
    ]);
}
```

### Adding a Callback for New Comments

[](#adding-a-callback-for-new-comments)

If you want a JavaScript function to be called when a new comment is added (e.g. to trigger some Analytics), first, create a global JavaScript function somewhere (i.e. one that is attached to the `windows` object):

```
window.onNewComment = function(comment) {
    console.log(comment);
}
```

Next, pass the function name when rendering:

```
{{ knp_disqus_render('your_disqus_shortname', {
    'identifier': '/december-2010/the-best-day-of-my-life/',
    'limit': 10,
    'newCommentCallbackFunctionName': 'onNewComment'
}) }}
```

SSO authentication (optional)
-----------------------------

[](#sso-authentication-optional)

If you want to manage authentication through [Disqus SSO](http://docs.disqus.com/developers/sso/) mechanism, you have to add the application secret key in the configuration and pass user information (id, username, email) which will compose the HMAC payload from it, as well as specific login/logout service information to the helper. Make sure to setup your Disqus forum to use SSO and allow for local domains (for development purposes).

To use SSO auth, pass `sso.user` information in the parameters to tell Disqus which user is logged in. Pass a user with an empty `id` to force Disqus to logout user, respectively to tell Disqus no user is logged in through SSO. Add information regarding your SSO Authentication service (login/logout urls, icon, etc.) in the `sso.service` parameter. See [Disqus SSO documentation](http://docs.disqus.com/developers/sso/) for more information.

```
{{ knp_disqus_render(
    'dolor-sid',
    {
        'identifier': '/december-2010/the-best-day-of-my-life/',
        'limit': 100,
        'sso': {
            'user': {
                'id' : 'test',
                'username' : 'John Doe',
                'email': 'john.doe@example.com',
            },
            'service': {
                'name': 'MyAuthServiceProvider',
                'icon': 'http://example.com/favicon.png',
                'button': 'http://example.com/images/samplenews.gif',
                'url': 'http://example.com/login/',
                'logout': 'http://example.com/logout/',
                'width': '400',
                'height': '400'
            }
        }
    },
    'KnpDisqusBundle::list.html.twig' )
}}
```

Configuration
-------------

[](#configuration)

```
# config/packages/knp_disqus.yaml
knp_disqus:
    api_key: 'your-disqus-api-key'
    secret_key: 'disqus-api-key' # optional, for SSO auth only
```

Enjoy!

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~303 days

Recently: every ~133 days

Total

12

Last Release

1627d ago

Major Versions

v1.1 → v2.02013-08-30

v2.4.0 → 3.0.02020-08-04

3.0.2 → 4.0.02020-09-08

PHP version history (5 changes)v1.0PHP &gt;=5.3.2

v1.1PHP &gt;=5.3.3

v2.4.0PHP &gt;=5.5

3.0.0PHP ^7.2.5

v4.1.0PHP &gt;=7.2.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/202732?v=4)[KNP Labs](/maintainers/KnpLabs)[@KnpLabs](https://github.com/KnpLabs)

---

Top Contributors

[![stloyd](https://avatars.githubusercontent.com/u/67402?v=4)](https://github.com/stloyd "stloyd (42 commits)")[![sadikoff](https://avatars.githubusercontent.com/u/213810?v=4)](https://github.com/sadikoff "sadikoff (31 commits)")[![weaverryan](https://avatars.githubusercontent.com/u/121003?v=4)](https://github.com/weaverryan "weaverryan (23 commits)")[![pilot](https://avatars.githubusercontent.com/u/28564?v=4)](https://github.com/pilot "pilot (17 commits)")[![esmiz](https://avatars.githubusercontent.com/u/751126?v=4)](https://github.com/esmiz "esmiz (12 commits)")[![mbontemps](https://avatars.githubusercontent.com/u/231249?v=4)](https://github.com/mbontemps "mbontemps (8 commits)")[![sauls](https://avatars.githubusercontent.com/u/7901434?v=4)](https://github.com/sauls "sauls (8 commits)")[![benoitpointet](https://avatars.githubusercontent.com/u/104787?v=4)](https://github.com/benoitpointet "benoitpointet (3 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (3 commits)")[![ralf57](https://avatars.githubusercontent.com/u/208237?v=4)](https://github.com/ralf57 "ralf57 (2 commits)")[![digitalkaoz](https://avatars.githubusercontent.com/u/293591?v=4)](https://github.com/digitalkaoz "digitalkaoz (1 commits)")[![umpirsky](https://avatars.githubusercontent.com/u/208957?v=4)](https://github.com/umpirsky "umpirsky (1 commits)")[![jlaso](https://avatars.githubusercontent.com/u/1332197?v=4)](https://github.com/jlaso "jlaso (1 commits)")

---

Tags

symfony-bundleforumcommentsdisqus

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/knplabs-knp-disqus-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/knplabs-knp-disqus-bundle/health.svg)](https://phpackages.com/packages/knplabs-knp-disqus-bundle)
```

###  Alternatives

[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1678.8M238](/packages/symfony-asset-mapper)[internal/dload

Downloads binaries.

102212.3k19](/packages/internal-dload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
