pagedown icon indicating copy to clipboard operation
pagedown copied to clipboard

Global resources not found when using custom template as package

Open jdbarillas opened this issue 3 years ago • 0 comments

Can you provide guidance into how I would pass resource dependencies to html_paged?

I'm trying to create a new format following the instructions found here in Chapter 18 so I can turn it into a package.

However, when I serve the document, the resources I've specified are not found. It does work if I add the supporting files to the skeleton template as detailed in Chapter 17.

I'd rather have a global set of custom files that are used in multiple templates rather than having a copy of each in each template, mirroring how pagedown's resources are kept.

Below is basically what I'm attempting.

my_report = function(
  ..., 
 # Pass custom css files
  css = c('custom-fonts.css', 'custom-page.css', 'custom.css'),
  template = pagedown:::pkg_resource('html', 'paged.html')
) {
 my_pkg_resource = function(...) {
  system.file('resources', ..., package = 'my_package', mustWork = TRUE)
}

  # Get their path within package
  css_custom = my_pkg_resource(file.path('css', xfun::with_ext(css, ".css")))

  pagedown::html_paged(
    ..., 
    # Pass custom css paths to html_paged
    css = css_custom, 
    template = template
    )
}

jdbarillas avatar Aug 14 '20 20:08 jdbarillas