Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable local partial templates that override global template #1897

Merged
merged 5 commits into from
Nov 24, 2021

Conversation

gadenbuie
Copy link
Contributor

Fixes #1893 by adding a src_path argument to find_templates() and passing pkg$src_path to this argument wherever find_templates() is called.

Two follow up questions:

  1. Would you like this feature documented anywhere specific? I looked around for a good place but didn't find a good fit — perhaps at the end of Customize - Template Packages?

  2. At this point find_templates() requires pkg for 3 of its arguments. I could refactor find_templates() to take pkg as an argument, likely the first argument in line with other functions in pkgdown. The only downside I see is that we'd end up calculating templates_dir a few more times than necessary if we call templates_dir(pkg) inside find_templates(). I don't think that would have a noticeable impact, though.

    I'd be happy to add the refactoring to this PR if desired.

Adds `src_path` argument to `find_templates()` and passes `pkg$src_path` to this argument wherever `find_templates()` is called
R/templates.R Outdated
@@ -2,14 +2,16 @@ find_template <- function(type,
name,
ext = ".html",
templates_dir = NULL,
bs_version = 3) {
bs_version = 3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's now the time to bite the bullet and pass pkg to this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'll add that change

existing arguments that require the `pkg` object are now calculated in `template_candidates()`
@hadley
Copy link
Member

hadley commented Nov 24, 2021

How about a new subsection at the end of https://pkgdown.r-lib.org/dev/articles/customise.html#additional-html-and-files — I think you could just briefly mention this as an option for experts. And can you please add a news bullet somewhere in https://github.com/r-lib/pkgdown/blob/HEAD/NEWS.md#customisation?

@hadley hadley merged commit 5d8b330 into r-lib:main Nov 24, 2021
@hadley
Copy link
Member

hadley commented Nov 24, 2021

Thanks!

@gadenbuie gadenbuie deleted the local-templates branch November 24, 2021 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow templates to be provided in the pkgdown/ directory
2 participants