How to reference a template in R?

52 Views Asked by At

I'm new to R, and I now I'm probably overthinking it and it's a stupid error, but I can't get around it and haven't found any helpful sources online.

I have been tasked to create templates for an R Quarto website. These templates have to be the basic "building blocks" of stuff that is repeated a lot throughout the website. Some examples of this are: a top navbar, a text block with 2 columns, etc. All of these templates have to be located in root_directory/_templates/templates.qmd. I'm trying to build a template for the top navbar. For now it looks like this: root_directory/_templates/templates.qmd

---
template: navbar
---
navbar:
    title: A title
    background: primary
    search: true
    reader-mode: true
    logo: "/images/image.png"

    right:
      - text: "Home"
        href: index.qmd
    tools:
      - icon: journal-text
        href: https://<an external link> .com/

root_directory/index.qmd

---
title: "Example_website"
template : navbar
---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.

root_directory/_quarto.yml

project:
  type: website

website:
  title: "Example_website"

format:
  html:
    theme: cosmo
    css: styles.css
    toc: true

output:
  dir: docs

templates:
  - navbar.qmd

I believe the issue is in root_directory/index.qmd on line 3, but I'm not sure. I have tried the implementation above and get:

ERROR: NotFound: The system cannot fin the specified file. (os error 2), stat 'root_directory\navbar'

I have also tried the following for index.qmd:

  1. template : _templates\navbar which leads to ERROR: NotFound: The system cannot fin the specified file. (os error 2), stat 'root_directory\_templates\navbar'

  2. template : _templates\templates.qmd::navbar which leads to ERROR: The name of the file, the name of the directory or the syntax of the volume tag are not correct. (os error 123), stat 'root_directory\_templates\templates.qmd::navbar'

  3. This is the closest I've gotten to a solution template : _templates\templates.qmd In which case the template is not displayed properly in the HTML output for index.html: root_directory\_site\index.html:

<html><head>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"></head><body>---
template: navbar
---
navbar:
    title: A title
    background: primary
    search: true
    reader-mode: true
    logo: "/images/image.png"

    right:
      - text: "Home"
        href: index.qmd
    tools:
      - icon: journal-text
        href: https://<an external="" link=""> .com/</an></body></html>

and it's displayed as in the image enter image description here

Please help, I'd be eternally grateful. Thanks

0

There are 0 best solutions below