I’m refactoring a site I didn’t build in the first place and i’ve hit a bit im not familiar with and i need to change it slightly… i don’t really understand it, despite reading the docs for r()
.
I have a snippet call like this:
<?php snippet('common/blog-disqus', ['disqus_shortname'=>'myshortname', 'disqus_developer' => r(c::get('live')== true, true, false)], true)?>
But it doesn’t seem to work. My live variable in the config is either true or false, whereas the old site this was set to a string. I think that stops disqus showing up at all on a dev environment. If i change the very last true right on the end to false, disqus loads on dev, so i know the snippet loads ok. I just need to fix it so it respects the config variable setting.
How do i make it work with a true or false?
First of all, the last true
doesn’t make sense, unless the snippet is stored in a variable.
$snippet = snippet('xy', [], true);
otherwise
<?php snippet('xy', []); ?>
As regards the rest, I’d need more context as to what is inside the snippet.
The snippet is pretty much just a standard Disqus include, with some things filled in from variables and Kirby…
<?php
// set the defaults
if(!isset($disqus_shortname)) die('Please pass the disqus shortname');
if(!isset($disqus_title)) $disqus_title = str_replace("'",'’', $page->title());
if(!isset($disqus_developer)) $disqus_developer = false;
if(!isset($disqus_identifier)) $disqus_identifier = $page->uri();
if(!isset($disqus_url)) $disqus_url = $page->url();
$disqus_title = addcslashes($disqus_title, "'");
$disqus_developer = ($disqus_developer) ? 'true' : 'false';
?>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '<?= $disqus_shortname ?>'; // required: replace example with your forum shortname
var disqus_title = '<?= html($disqus_title) ?>';
var disqus_developer = '<?= $disqus_developer ?>'; // developer mode
var disqus_identifier = '<?= $disqus_identifier ?>';
var disqus_url = '<?= $disqus_url ?>';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
The original snippet call was like this:
snippet('disqus', ['disqus_shortname'=>'myshortname', 'disqus_developer' => r(c::get('env')=='dev', true, false)], true);
I solved it another way. Seems that embed code for Disqus is quite old and the current version can detect localhost and not load itself accordingly. I have upgraded the embed code.