Accessing params from partial

Haven’t found a way to do this. I am missing something?

I’m trying to access a Params.SOMETHING that’s in my _index.md content folder from within a partial.

content/issue_1/_index.md

---
Title: issue 1
Editor: Rick Hunter, from Robotech.
---

Trying to access from:
partials/template-styles/regular-template.html

{{ .Params.Editor }}

Shows nothing at all. No error, no nothing.

What could be wrong?

Now, here’s The path to regular-template file in which I am making that call:
/layouts/_default/section.html

{{ partial "article.html" .  }}

And within this article.html, I have a partial call:
/layouts/_partials/article.html

{{ partial "template-styles/regular-template.html" .  }}

The period is on the end of everywhere, but the variable from _index.md doesn’t seems to be able to go through from section.html (where if I do {{ .Params.Editor }} , Rick Hunter the brave Valkyrie pilot shows up), but it doesn’t reaches the "article.html" page that gets called from within "section.html", even though the damn dot is there!

Try {{ .Params.editor }}.


Page-level .Params are only accessible in lowercase.

First thing I tried, but it didn’t worked ;-( It doesn’t! Thanks for the input though.

It’s easier to help you debug this if you could just share a git repo with minimal example.

Right now, one needs to copy/paste your snippets and create the minimal example themselves. After all the effort, if someone is not able to reproduce the issue, they will ask you to post a repo then.

More likely than not, the issue is usually something else, that the OP did not put in their snippets.

It saves a lot of time for the person needing help as well as the helpers if a git repo is shared to begin with.

FWIW, I cannot reproduce this issue.

I did not copy/paste your snippets. But I simply added “Editor” front-matter to a test page, and I can access it via .Param "Editor" and .Param "editor".

1 Like

Perhaps the problem is with nested partials?

My html output comes from a partial that’s nested. On the root level of the partials folder, I can access the variable, but if I go one level deep, then I can’t.

Three ways of solving this, out of the top of my mind:

1) I will drop the folder “template-styles” and simply name my partials as “TEMPLATE-name” for simplicity sake (although I kinda liked to have everything neatly organized in folders)
2) I can create a dict for each one of those variables I need from _index.md (at the moment, something in the vicinity of 14)
3) Cry on my pillow for the rest of the day.

Since I’m not going to be creating a lot of templates for this one, I will do the first option (though I was already half way there with the second one…)

Just tried it, doesn’t works outside partials either (thought I’d seen it work). I’m going with option 2.

Again, can’t stress this enough. Please create a minimal example git repo and share it.

It’s possible that you could have discovered a bug. But no one can say that for sure unless they can reproduce it.

So share the repo -> possibly uncover a bug -> get it fixed in Hugo.

After going through my code for a while, this is 100% sure a bug. I’m filling a report.