How to pass dict from partial call to $related?

I’m trying to reuse partial b passing variables from dict to html componenet and $related method.

{{ partial "index/column-style1" (dict "category" "State") }}
I can access this variable at html level
<h4><span>{{ .category }} News</span></h4>
But can’t use it here
{{ $related := .Site.RegularPages.RelatedTo ( keyVals "tags" "USE_category_HERE" "state")}}

Can someone help me out with this?

You need to pass the dot . context.

{{ partial "index/column-style1" (dict "ctx" . "category" "State") }}

now you can access it from ctx.

{{ $related := .ctx.Site.RegularPages.RelatedTo ( keyVals "tags" "USE_category_HERE" "state")}}

I tried .ctx.category and still can’t get the value. I must be doing something wrong.

No need to use ctx namespace, you pass the category key directly.

1 Like

That works. But now how do I access this in HTML element {{.category}} gives me error

Edit: I did it by {{$.category}}

Complele solution:
Access it in HTML by {{$.category}}
and it functions by simple .category

pamubay Thanks for your answer

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