Template is not fully rendering

Hello,

I have this partial template for disqus in a single page post:

{{ if isset .Site.Params "Disqus" }}
<div id="disqus_thread"></div>
<script type="text/javascript">
  (function() {
    if (window.location.hostname === "localhost") {
      return;
    }
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    var disqus_shortname = '{{ .Site.Params.Disqus }}';
    var disqus_identifier = '{{ with .Params.disqusIdentifier }}{{ . }}{{ else }}{{ .PublishDate.Format $.Site.Params.ISO8601 }}{{ end }}';
    var disqus_url = '{{ .Permalink }}';
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    document.getElementById('disqus_thread').appendChild(dsq);
  })();
</script>
{{ end }}

When .Params.disqusIdentifier isn’t always available, I want to use the page’s published date in IOS8601 format (or any other date format) as the id.

For some reason the page is only rendering part of the template. I’m not getting an error in the watch console. This is the rendered output:

<script type="text/javascript">
  (function() {
    if (window.location.hostname === "localhost") {
      return;
    }
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    var disqus_shortname = 'foobar';
    var disqus_identifier = '

What is wrong with my template? Thanks!

IIRC, keys in Params are lowercased, so you might need

    var disqus_identifier = '{{ with .Params.disqusidentifier }}{{ . }}{{ else }}{{ .PublishDate.Format $.Site.Params.iso8601 }}{{ end }}';

Thanks for pointing that out. I played around with that section and noticed it’s something with the date part. The code seems to render just fine when I remove this part:

{{ .PublishDate.Format $.Site.Params.iso8601 }}

Any clues? Thanks!

Hmm… You might try just printing the value of that parameter to make sure it contains a valid format:

{{ $.Site.Params.iso8601 }}

You’re right. I had to do {{ .PublishedDate.Format "2006-01-02T15:04:05Z07:00" }}. That’s a little weird for me coming from different languages where I can use a constant. Is there a way to access date constants like iso8601?

Do you have a params section in your main config file? (Specifically with iso8601/ISO8601 set there)

No of course not. Why should I? Shouldn’t this be a standard constant?

It is a standard constant in Go (as time.RFC3339), but it’s not exposed by Hugo.

Site.Params is filled in from your config.{toml,json,yaml}.

I understand that. I’m saying maybe there should be a request to make these constants exposed so users don’t have to dig them up and set them manually :slight_smile: