I’m looking for the idiomatic way to say “show me something if the user has a Twitter account and has asked to show recent tweets.”
I’m using a partial for this:
{{ "<!-- hugo: enter partials/twitter/recent.html -->" | safeHtml }}
{{ with .Site.Params }}
{{ if and (isset . "twitter") (isset .twitter "account") }}
{{ $account := .twitter.account }}
{{ with .theme.twitter.recent }}
<section>
<h1>Latest Tweets</h1>
<ul id="tweets" data-user="{{ $account }}" data-count="4" data-replies="false">
<li class="loading">Status updating...</li>
</ul>
<a href="//twitter.com/{{ $account }}" class="twitter-follow-button" data-show-count="false">Follow @{{ $account }}</a>
</section>
{{ end }}
{{ end }}
{{ end }}
{{ "<!-- hugo: leave partials/twitter/recent.html -->" | safeHtml }}
My config.toml
has separate sections for the Twitter account information and the theme settings for displaying the Twitter feed:
[Params.twitter]
account = "mdhender"
[Params.theme.twitter]
recent = "true"
That makes sense to me since the theme needs to be plumbed to support Twitter, even if the particular user doesn’t have a Twitter account. I’m still digesting the thread on http://discuss.gohugo.io/t/hugo-seo-social-partials/353/15 [Hugo SEO/Social Partials], so I may change the config, but for now the question is about expressing that logic in Hugo.