Get support for KnpLabs/KnpDisqusBundle
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
KnpLabs/KnpDisqusBundle
KnpDisqusBundle
If you use Disqus 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.
Requirements
- Disqus API: public key
Installation
With composer, 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:
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:
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
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)
If you want to manage authentication through Disqus 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 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
# config/packages/knp_disqus.yaml
knp_disqus:
api_key: 'your-disqus-api-key'
secret_key: 'disqus-api-key' # optional, for SSO auth only
Enjoy!
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2