Hello everyone. I’m new to Hugo. I can’t understand .Data
in Page variables in the document
.Data
the data specific to this type of page.
I’ve tried to console log .Data but I only get {}
Can someone help me understand what’s this for?
Hello everyone. I’m new to Hugo. I can’t understand .Data
in Page variables in the document
.Data
the data specific to this type of page.
I’ve tried to console log .Data but I only get {}
Can someone help me understand what’s this for?
Place this in baseof.html:
.Data = {{ printf "%v" .Data }}<br>
.Data.Pages = {{ printf "%v" .Data.Pages }}<br>
.Pages = {{ printf "%v" .Pages }}<br>
Then visit:
1) On single pages:
.Data
is an empty map..Data.Pages
is an empty page collection.Pages
is an alias to .Data.Pages
In some older themes, before the
.Pages
alias was available, sometimes you will still see:{{ range .Data.Pages }}
2) On the home page or section pages:
.Data
is a map containing a pages
element.Data.Pages
is the page collection available to the current page.Pages
is an alias to .Data.Pages
3) On taxonomy pages:
.Data
is a map containing the following elements: Plural
, Singular
, Terms
, pages
, etc. See documentation.Data.Pages
is the page collection available to the current page.Pages
is an alias to .Data.Pages
4) On term pages:
.Data
is a map containing the following elements: Plural
, Singular
, Term
, pages
, etc. See documentation.Data.Pages
is the page collection available to the current page.Pages
is an alias to .Data.Pages
Thank you @jmooring. This is an AWESOME answer.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.