[SOLVED] The dict function and "the dot" / global context

Hi there! Thanks for stopping by :slight_smile:

Anyone knows how I’d be able to call a global parameter on a nested template definition that uses (dict) like so: {{ template "bem" (dict "class" "introduction" "vibe" "1" "layout" "1") . }}?

The template itself is as follows:

{{ define "bem" }}
  {{ if eq .vibe "1" }}
    {{ if eq $.Site.Data.configuracoes.identidade.vibe "edgy"}}
      {{ .class }}_edgy
    {{ else if eq $.Site.Data.configuracoes.identidade.vibe "light"}}
      {{ .class }}_light
    {{ end }}
  {{ end }}
  {{ if eq .layout "1"}}
    {{ if eq .Params.template 2}}
      {{ .class }}_parallax
    {{ else if eq .Params.template 1}}
      {{ .class }}_split
    {{ end }}
  {{ end }}
{{ end }}

The idea behind this is I’ll be automatically updating the HTML classes for specific blocks in my DOM, according to the BEM naming methodology. The {{ if eq .Params (...) and the {{ if eq $.Site.Data (...)conditionals work perfectly if I remove the dict parameters… Do you think maybe the dict function conflicts with the context dot?

It’d be great if you could help! :smiley:


So, I’ve finally managed to figure out how to search for this issue, and apparently there’s no way to pass dict and global variables at the same time:frowning:
Do you have any suggestions on how I could do this naming function?

I think you want something like this:

{{ template "bem" (dict "context" . )  }}

Then, where you’d have the dot in your template, use context. instead of just the dot.


Worked perfectly, budparr!! Thanks so much, made my night :smiley:

1 Like