0

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?

Andry
  • 16,172
  • 27
  • 138
  • 246

1 Answers1

1

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!

Andry
  • 16,172
  • 27
  • 138
  • 246
  • 1
    Or use R to read your config file, then embed an inline R expression. – Yihui Xie Feb 22 '19 at 23:10
  • @YihuiXie It's an honor to "meet" you sir! Amazing work, I am liking it so much :) Please post it as an answer, you comment I mean, because I will probably go for it and that is a valid approach I will mark here. Thanks! – Andry Feb 23 '19 at 07:13
  • Thanks for the kind words! I think both approaches should work, and I don't really have a preference. Just use the one that works for you. – Yihui Xie Feb 25 '19 at 05:39