Can't make isset work as key membership test

Hi,
this branch so far

{{- else if isset $map .Destination }}
	<span class="{{index $map .Destination }}">{{.Text}}

considering {{- $map := dict "V" "bascule" "OR" "overline" -}}
has only tested negative with strings like [sdfsd](V). I read the definition and don’t understand how it works.

  • With page .params
    Keys have to be all lowercase (see collections.IsSet and the example/warning)
    guess render-hooks, list templates shortcode parameters count in here except if for dictes passed.

  • With a map:
    Keys have to be same case as in definition
    mmh, that’s behaving different (map == dict ↔ collection ???)

p.s. always good if text, and code of an issue match each other :wink:

<tl;tr>

have a look at the results (code in hidden details below)

Page front matter (.Params)

title = "Hello World"
[params]
V = "bascule"
OR = "overline"

Map definition

$map := dict "V" "bascule" "OR" "overline"

Results

WARN  map        V -> true
WARN  map        v -> false
WARN  map       OR -> true
WARN  map       or -> false
WARN  map       Or -> false
WARN  map       .y -> false
WARN  map       .Y -> false
WARN  map     oops -> false
WARN  param      V -> false
WARN  param      v -> true
WARN  param     OR -> false
WARN  param     or -> true
WARN  param     Or -> false
WARN  param  title -> true
WARN  param  Title -> false
WARN  param   oops -> false
Home Template
{{- define "main" }}
  <h4>MAP</h4>
  <pre>
    $map := dict "V" "bascule" "OR" "overline"
  </pre>

  {{- $map := dict "V" "bascule" "OR" "overline" }}
  <ul>
  {{- range slice "V" "v" "OR" "or" "Or" ".y" ".Y" "oops" }}
    {{ $result := printf "map   %6s -> %v" . (isset $map .)}}
    <li>{{ $result }}</li>
    {{- warnf $result }}
  {{- end }}
  </ul>

  <h4>Page.Params</h4>
  <pre>
title = "Hello World"
[params]
V = "bascule"
OR = "overline"
  </pre>

  <ul>
  {{- range slice "V" "v" "OR" "or" "Or" "title" "Title" "oops" }}
    {{ $result := printf "param %6s -> %v " . (isset $.Params .)}}
    <li>{{ $result }}</li>
    {{- warnf $result }}
  {{- end }}
  </ul>
  {{- end }}

So it should be working.

think so. the shown code is tested.

if not for you, you’ll have to come up with the real code and config setup to reproduce

I didn’t change anything and now it works and I feel stupid. I swear ! I’m not crazy ! Jeez…

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.