.Store empty after server restart

Although .Store should maintain the content after a re-rendering of the page, it seems that it does not.
The content disappears when I change the content of the _index.md file.

I have this _index.md:

+++
title = "Solutions"
type = "page"
description = ""
weight = 100
layout = "solutions"
+++

{{< content home >}}
This is the content inside the `top` shortcode, which will be captured for use in the template.
{{< /content >}}

This shortcode stores the content in .Store:

{{ $loc := .Get 0 }}
{{ $.Page.Store.Set $loc .Inner }}

And this is the template solution.html:

{{ $home := "" }}
{{ with .Page.Store.Get "home" }}
    {{ $home = . | safeHTML }}
{{ end }}

{{ $home }}

It works perfectly, but as soon as I change _index.md, the content is not rendered anymore.

This is strange because it behaves like .Scratch.

Thank you for the help!

Is there a “top” shortcode, or is the text incorrect? Assuming there isn’t a “top” shortcode, I suspect you are trying to access Store before the page content has been evaluated.

Force the content to be evaluated before accessing the Store.

layouts/_default/solutions.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>

  {{ $home := "" }}
  {{ $noop := .WordCount }}  <---------- FORCES CONTENT EVALUATION
  {{ with .Page.Store.Get "home" }}
    {{ $home = . | safeHTML }}
  {{ end }}
  {{ $home }}

  {{ .Content }}
  {{ range .Pages }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}
{{ end }}

I guess they were referring to the shortcode above – top being a location, not a name

1 Like

It works perfectly.
Thank you!

BTW, “top” had no particular meaning. It was only part of the different test text I created :wink:

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