Hello,
how can I refer a custom variable sitting in the frontmatter of a document in the layout the document uses to be rendered?
The sample:
in the folder “movz” I want a series of pages each one having its own video (hosted and linked on archive.org). I thought I could put the link to the video in the toml frontmatter of each document archivelink = "mylink"
, then build the page with the layout “movz/single.html” (or a partial) that should call that link:
<iframe src="{{ .Params.archivelink }}" width="640" height="480" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen>
</iframe>
As in a previous similar post, I can’t get to reference these variables. I tested many “combinations” but I guess I’m missing the steps to reference a node from another.
{{ .Params.archivelink }}
{{ .archivelink }}
{{ .archivelink . }}…
I get only errors.
Is there any tutorial other than the manual?
Thank you.
Can you show more of your template and frontmatter? The .Params.archivelink
usage looks correct.
thanks. I strated from the theme hugo-theme-nix-master. Inside content/mov/ one of my file is pressmanhat.md which is
+++
date = "2016-12-11T09:44:15+01:00"
title = "how to fold a pressman's hat"
categories = [
"Movies",
"How to"
]
[menu.main]
name = "How to fold a pressman's hat"
weight = 110
archivelink = "https://archive.org/embed/HowToFoldANewspaperPressmanHat_201603"
+++
# How to fold a pressmanhan's hat.
then I have a layout, based on “index”, into layouts/mov/single.html wich contains, among the rest:
<div class="col-sm-3 col-centered">
<!-- TEST -->
<p>test: get value from front matter! -> {{ .Params.archivelink }}</p>
<!-- actual code from archive.org to incorporate movies,
wich I want in a layout or partial for easy editing for all the movie documents I will publish -->
<iframe src="{{ .Params.archivelink }}" width="640" height="480" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen>
</iframe>
</div>
The server doesn’t give any error, and in the ouput I found:
<div class="col-sm-3 col-centered">
<p>test: get value from front matter! -> </p>
<iframe src="" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen="" width="640" height="480" frameborder="0">
</iframe>
</div>
so no ouput from my “archivelink” variable.
Thank you for your help
The problem is the frontmatter formatting. In TOML format, everything after the [menu.main]
becomes a child of that section. Move archivelink
up above the [menu.main]
section, and it should work.
Great now it works, thank you very much.
To avoid such problem are maybe Yaml or Json more powerfull?
Thank you again
I don’t know that they’re more powerful, but they’re available if you want to use them. I don’t like hand-editing JSON. I prefer TOML just because YAML is sensitive to whitespace.
Thank you all, I’m marking the post as solved