Page variable | partials | nested cascade

Just to be clear, when passing context from partials built from frontmatter cascades to the partials they call, the new page variable does not give access to variables in the cascade?

frontmatter:

title="A Block of Text"
custom="custom parameter"
[[block]]
section="one"
name="two"
image="three.jpg"

default list

{{- $dot := .Page -}}

{{- range $.Page.Params.block -}}
{{- partial (printf `%s%s%s%s` .section   "/"  .name ".html" ) (dict "context" . "pageContext" $dot ) -}}
{{- end -}}

The old way:
partial/one/two.html

{{- .context.image  -}}

{{- .pageContext.Params.custom -}}


The new way:
partial/one/two.html

{{- page.Title -}}
{{- page.Params.custom -}}
{{- page.Params.block.image -}}

Everything above renders except page.Params.block.image.

Can we access cascade variables from the new page function?

The page function gives you access to the top-most page context.

content structure

content/
├── posts/
│   ├── post-1.md
│   ├── post-2.md
│   └── post-3.md
└── _index.md

layouts/home.html

{{ range site.Sections }}
  {{ range .Pages }}
    {{ page.Title }}
  {{ end }}
{{ end }}

This will print the title of content/_index.md (the home page) three times.

Hey jmooring thanks for fielding this query.

If that is the case, the ‘page’ function is not relevant.

The code should associate sections of the page with partials called from ‘blocks’ in frontmatter. Pancaked blocks.

frontmatter:

+++

title="A Block of Text"
custom="custom parameter"

[[block_1]]
section="blocks"
name="one"
varRelevantPartialOne="image.jpg"

[[block_2]]
section="blocks"
name="two"
varRelevantPartialTwo="image2.jpg"

+++

layouts/_default/list.html:


{{- define "left" -}}{{- partial "left/left-list" . -}}{{- end -}}

partials/left/left-list.html


{{- if $.Page.Params.block_1 -}}

{{- range $.Page.Params.block_1 -}}
{{- partial (printf `%s%s%s%s` .section   "/"  .name ".html" ) . -}}
{{- end -}}

{{- end -}}

partials/blocks/one.html etc


{{/* Access to frontmatter, including variables in blocks. */}}


Each partial should have access to frontmatter, as should the partials they call; however that part works (see above), thanks to someone’s comments earlier.

It’s the references to the cascaded parameters that are problematic.

If I understand correctly, you prefer a simple github repo example to clone:

Sadly, Github sold me on the repo name:

https://github.com/8f5bec34/githubs-fluffy-octo-spoon.git

From what you’ve posted and shared in the test repo, you don’t have any “cascaded” parameters. Please clarify.

Yes, then that is the problem.

I am referring to the TOML structure for arrays of key value pairs, '[[block_1]]', which if I understand correctly is equivalent to the following json structure:

{ "block_1": [                   
{
"section"="blocks",
"name"="one",
"varRelevantPartialOne"="image.jpg"        
}
]}

In some cases the partials should be stacked in one range.

+++
[[block_1]]
section="blocks"
name="one"
varRelevantPartialOne="image.jpg"

[[block_1]]
section="blocks"
name="two"
varRelevantPartialTwo="image2.jpg"

+++

In other cases, based on html, they should be in separate ranges.

+++
[[block_1]]
section="blocks"
name="one"
varRelevantPartialOne="image.jpg"

[[block_2]]
section="blocks"
name="two"
varRelevantPartialTwo="image2.jpg"

+++

While the config wants this structure:

[params]
[[params.block_1]]
section="blocks"
name="one"
varRelevantPartialOne="image.jpg"

[[params.block_2]]
section="blocks"
name="two"
varRelevantPartialTwo="image2.jpg"


That did not work out in the frontmatter.

This reference appears successful in some cases; but in other cases less so.

$.Page.Params.block_1 or $.Page.Params.block_2

When I build the site locally, changing the color scheme and adding some line breaks so I can actually see what is rendered compared to front matter and array iterations, everything looks correct to me.

Yes, based on todo list I just used the primary colors for the 3 blocks and yellow for the default block. In my case the yellow runs.

However, if [[block_1]], [[block_2]], or [[block_3]] are in the frontmatter the partials they reference should print text and html to the screen.

The yellow should print only in the case when [[block_3]] is absent in frontmatter.

In my case, the three blocks are present but they do not print, only the default prints.

This is what I see when I visit /posts/

The only changes I made were aesthetic.

It is working in posts. I do not use ‘hugo new’ command often, I was looking in root.

Then the code works as it should.

It is not rendering correctly in the staging site, with reference to the correct directory.

There is then some other problem.

Thanks

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