I just started using Hugo with the Kiss template, but I cant seem to get variables to work.
In my page, I defined the variable imgPad here:
---
title: "Hugo Blog on Azure"
date: 2018-12-09T15:51:09-05:00
draft: false
imgPad: 14
---
Below, I try to use it like this:
<img alt="Deploy to Static Website" src="img/hugo-blog-on-azure/azure_storage_deploy.png" style="width: 500px; display:block; padding: {{ .imgPad }}"/>
In the browser the {{ .imgPad }} does not get replaced with anything. What could be the problem?
Thanks.
Look at Page Level Params
It needs to be accessed as
{{ .Params.imgpad }}
Note the lower case.
Didn't work for me, I get this as a result in the browser:
<img alt="Successful deployment" src="img/hugo-blog-on-azure/azure_storage_deploy2.png" style="width: 500px; display:block;
padding: {{ .Params.imgPad }}">
^^^^^^
There still is an uppercase letter.
As described in this thread, use in your fragment template, and in your front-page only lowercase variables.
Example:
ingredients:
- ingredient: Club Soda
amount: 4oz
- ingredient: Gin
amount: 2oz
- ingredient: Lemon Juice
amount: 1oz
- ingredient: Simple Syrup
amount: 1tsp
and
{{ range .Params.ingredients }}
{{ .ingredient }} {{ .amount }}
{{ end }}
Every variable is in lowercase here.
Related
According to the Hugo content summary guide, I can define a summary in 3 ways (listed in order of highest preference):
Use the <!--more--> tag to tell how much of the article Hugo should use as the summary
Use the summary variable in the front matter in order to use a custom summary
Let Hugo by default use the first 70 words of the article
First and foremost, here is the template I have for individual pages:
{{ partial "header" . }}
{{ partial "nav" . }}
<section class="section">
<div class="container">
<div class="subtitle tags is-6 is-pulled-right">
{{ if .Params.tags }}
{{ partial "tags" .Params.tags }}
{{ end }}
</div>
{{if not .Date.IsZero }}
<h2 class="subtitle is-6">{{ .Date.Format "January 2, 2006" }}</h2>
{{ end }}
<h1 class="title">{{ .Title }}</h1>
{{ if .Site.Params.Info.related }}
<div class="related">{{ partial "related" . }}</div>
{{ end }}
<div class="content">
<h1 id="summary">Summary</h1>
{{ .Summary }}
<h1 id="toc">Table of Contents</h1>
{{ .TableOfContents }}
{{ .Content }}
</div>
</div>
</section>
{{ partial "footer" . }}
Here is a sample article I made:
---
title: "Test"
date: 2019-11-23T19:51:44-06:00
draft: true
summary: "This is a simple placeholder summary defined in the front matter"
---
This is a simple placeholder written in the article
# Section 1
Hello world!
The title and date render just fine, however, the summary is ignored and the words from the article as used as the summary:
I then used the <!--more--> tag like so:
---
title: "Test"
date: 2019-11-23T19:51:44-06:00
draft: true
summary: "This is a simple placeholder summary defined in the front matter"
---
This is a simple placeholder written in the article
<!--more-->
# Section 1
Hello world!
It worked like a charm...
So methods 1 and 3 for content summaries work, but method 2 does not. Is there a reason why I can't get the summary front matter to render?
This feature was introduce in Hugo 0.55.0 via issue #5800.
Upgrade to Hugo 0.55.0 or above to solve the issue
I've been experimenting with finding a fix for a new deprecation error that occurs with Hugo version 0.55.5:
.File.BaseFileName on zero object. Wrap it in if or with: {{ with .File }}{{ .BaseFileName }}{{ end }}
The two affected snippets of code in question:
{{ $header := print "_header." .Lang }}
{{ range where .Site.Pages "File.BaseFileName" $header }}
{{ .Content }}
{{else}}
{{ if .Site.GetPage "page" "_header.md" }}
{{(.Site.GetPage "page" "_header.md").Content}}
{{else}}
<a class="baselink" href="{{.Site.BaseURL}}">{{.Site.Title}}</a>
{{end}}
{{end}}
&& the footer:
{{ $footer := print "_footer." .Lang }}
{{ range where .Site.Pages "File.BaseFileName" $footer }}
{{ .Content }}
{{else}}
{{ if .Site.GetPage "page" "_footer.md" }}
{{(.Site.GetPage "page" "_footer.md").Content}}
{{end}}
{{end}}
I've been attempting different variations of wrapping those segments of code with {{ with .File }} as the error message suggests, but it isn't liking anything I've been coming up with. As an example, if I put that surrounding bit of code around the {{ range ... }} statement, I get the error: can't evaluate field Site in type source.File. If someone could assist in figuring out where {{ with .File }} should be placed, it would be greatly appreciated.
You get this error
can't evaluate field Site in type source.File
Because the context changes when inside with. To fix it, wrap your code in a {{ with .File }} as you mentioned.
Then everywhere you're using .Site, replace it with site.
Then make sure you're using Hugo version 0.53.0 or higher, so that the site keyword is available.
I have a relation field in netlify-cms which prints out my multiple selected related pages. Im struggling to get hugo to go through the loop and grab the title from each page using a combo of range/GetPage.
My broken Example:
{{ range .Params.chassis.availableChassis }}
{{ with .Site.GetPage "/chassis/" . }}<h1>{{ .Title }}</h1>{{ end }}
{{ end }}
Page content:
chassis:
availableChassis:
- Nissan
- Renault
NetlifyCMS field setup:
- {label: "Chassis", name: chassis, widget: object, fields: [
{label: "Available chassis", name: "availableChassis", widget: "relation", collection: "chassis", searchFields: "title", valueField: "title", required: false, multiple: true}
]}
If i do this i get the page title from the page, but obviously its not dynamic based on CMS choice:
{{ with .Site.GetPage "/chassis/nissan" }}<h1>{{ .Title }}</h1>{{ end }}
Possibly an easier solution ive not thought of or im not looking in the right place in the docs.
Created a solution using GetPage, open to alternatives or less chunky solutions
{{ $chassis := .Params.chassis.availableChassis }}
{{ range where .Site.Pages "Type" "chassis" }}
{{ $page := . }}
{{ range $chassis }}
{{ if in $page.Title . }}
{{ with $.GetPage $page.File.Path }}
{{ .Params.hero.heroTitle }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
I understand ng-show/ng-hide can be used but this case is a little different. This is my script below. Basically what I'm trying to do is hide the word "PEAK" if 'info.peak' value is empty in the title tag. DO I need to create two versions of this image tag? One with and without 'peak'? If show How would I do that also?
<img
class="icon lazyloaded"
data-ng-src="{{ info.image }}"
alt="{{ info.title }}"
title="Last Week: {{ info.lastweek}} Move: {{ info.move }} Peak: {{ info.peak }}"
width="100"
height="100">
You can do this with the following:
{{ info.peak ? 'Peak: ' + info.peak : '' }}
in place of where you have Peak: {{ info.peak }}. So if info.peak does not exist/is null, it will simply append an empty string to the end.
This is regarding https://docs.angularjs.org/guide/interpolation#known-issues
The documentation says that "Your changes are likely to be overwritten, when the original string gets evaluated."
With the example:
style="color: {{ 'orange' }}; font-weight: {{ 'bold' }};")
Can someone please explain what documents is trying to highlight?