Searching for an idiom to deal with Params testing

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 }}
        <h1>Latest Tweets</h1>
        <ul id="tweets" data-user="{{ $account }}" data-count="4" data-replies="false">
          <li class="loading">Status updating...</li>
        <a href="//{{ $account }}" class="twitter-follow-button" data-show-count="false">Follow @{{ $account }}</a>
    {{ 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:

	account = "mdhender"
	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 [Hugo SEO/Social Partials], so I may change the config, but for now the question is about expressing that logic in Hugo.

1 Like