I’m trying to print the output of a variable inside this template:
{{- $menu := .Site.Params.sectionPagesMenu | default "main" -}}
I’m not sure what is the correct format to do that. Thank you for your suggestions.
I’m trying to print the output of a variable inside this template:
{{- $menu := .Site.Params.sectionPagesMenu | default "main" -}}
I’m not sure what is the correct format to do that. Thank you for your suggestions.
I don’t know what that means.
{{ myVariable := 42 }}
{{ $myVariable }} --> prints "42"
I tried the approach you suggest, but it outputs nothing. Is there a way to enable debug mode into all templates to display all variables while running the hugo server
?
Or another way that I could accomplish my validation, how do I print all .Site
variables through browser console? I added the following lines into header but the output is minimalist:
var hugoLog = JSON.parse({{ jsonify . }});
console.log('Hugo Debug: ', hugoLog);
No
Does it ouput nothing or display nothing?
{{ $myVariable | warnf "%v" }}
This one is the current context so Page. From your screenshot. Use site or .Site instead.
@irkode just to make sure I understand, I should have:
var hugoLog = JSON.parse({{ jsonify .Site }});
Is that correct?
That won’t work, and there’s no way to do what you want to do, with either Page
or Site
objects.
This only returns a subset… it’s incomplete:
<pre>{{ jsonify (dict "indent" " ") .Page }}</pre>
These return nothing because (internally) the Site
object is wrapped:
<pre>{{ jsonify (dict "indent" " ") .Site }}</pre>
<pre>{{ jsonify (dict "indent" " ") site }}</pre>
Going back to your original question…
The answer is still no.
Thank you @jmooring. So there is no way for me to have a list of all .Site variables, on each page. I’m wondering how developers debug the .Site variables.
Debug what? These values are immutable.
@jmooring I’m simply trying to display on each page what are the .Site values present, as I have several modules with each having additional settings.
If you’re talking about site parameters, inspect .Site.Parameters
.
If you’re talking about configuration settings, most aren’t exposed to the templates anyway.
If you’re intent of having a complete map of exposed settings you’ll need to build the map yourself.
Thank you @jmooring. I’m wondering if there is a tutorial for this, I’ve been searching for a solution but could not find anything.
For what?
For that.
{{ $siteMap := dict
"BaseURL" .Site.BaseURL
"BuildDrafts" .Site.BuildDrafts
.etc.
}}
A post was split to a new topic: Select menus based on directory structure
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.