Sorry, this is possibly an HTML question not a Hugo question … I’m more of a backend developer. It just seems to me that there should be a very easy solution to this.
HTML document has an attribute data-theme.
I wish to propagate it to a grecaptcha statically:
Hmm … thanks for responding. When you say “tokens”, I’m assuming that’s the same as HTML attributes? I’m not that experienced to know the term tokens.
So the thing is, this is a dynamic state - if the individual toggles the theme from light to dark, it’s no longer consistent with {{ .Site.Params.theme }} or somesuch.
Hugo outputs static HTML. A parameter for {{ .Site.Params.theme }} is consumed by the templates during the generation of HTML (or another output format). Therefore I do not understand your question.
Probably I misunderstood the original post because you typed data-sitekey="{{ . }}", so I assumed that you are trying to pass an access token for recaptcha
The propagation is fine using CSS for everything else … the issue is that I can’t get the captcha to pick it up upon creation in the HTML statically. If I need to I can create the captcha dynamically and give it the parameter … but I was hoping the static creation would work and I was just not experienced enough to know how this is done. My guess is that this might be outside of the province of Hugo to help and perhaps I should post on Stack Overflow.
It’s all good folks, I bit the bullet and switched over to explicit rendering of the captcha:
{{ with .Site.Params.contactFormReCaptchaSiteKey }}
<div id="g-recaptcha"></div>
{{ end }}
{{ with .Site.Params.contactFormReCaptchaSiteKey }}
<script>
// Captcha rendered dynamically to deal with some rendering issues with
// theme and with animation.
function captchaLoadCallback() {
grecaptcha.render( 'g-recaptcha', {
sitekey: '{{ . }}',
callback: onSubmit,
size: 'invisible',
badge: 'bottomright',
theme: $('html').attr('data-theme'),
});
}
</script>
<!-- Explicit rendering of recaptcha to deal with data-theme and animation issues -->
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?onload=captchaLoadCallback&render=explicit" async defer></script>
{{ end }}