Andry
Andry

Reputation: 16845

Cannot use a variable in Rmarkdown file in Bookdown/Hugo

I have created a simple website using Bookdown. I have a page:

---
title: Home
---

# Page title    
Lorem ipsum dolor sit amet.

However, instead of Page title I wanna show a value coming from my config.toml file.

What I tried

I want to show the value of a site variable, defined in config.toml file, so I did:

---
title: Home
---

# {{ $.Site.Params.author }}
Lorem ipsum dolor sit amet.

Having my configuration file like this:

[params]
    author = "Me myself and I"
    description = "My website"

However the value is not resolved. It is my understanding that I need to use a template, however, there is really no way to have a variable inside a content file?

Upvotes: 0

Views: 56

Answers (1)

Andry
Andry

Reputation: 16845

A possible way I found to do this is via shortcodes:

  1. I created a shortcode inside layouts/shortcodes like: myvar.html and placed there the string I want to emit
  2. Referenced the shortcode from the Rmarkdown file

The content file will look like:

---
title: Home
---

# {{< myvar >}}
Lorem ipsum dolor sit amet.

That worked!

Upvotes: 1

Related Questions