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

The directory.html template should be added in locals #95

Open
ghuser opened this issue Oct 21, 2019 · 3 comments
Open

The directory.html template should be added in locals #95

ghuser opened this issue Oct 21, 2019 · 3 comments

Comments

@ghuser
Copy link

ghuser commented Oct 21, 2019

In case someone wants to add extra content (e.g. an additional script ) in the existing template, it would be good to be able to do it also from inside template function (instead of copying/editing the default template). To achieve this, the default template should be added in locals object passed to template function.

The advantage of this is that on a later package upgrade, the template will be always up-to-date with the authors' version (plus the edits).

@dougwilson
Copy link
Contributor

Hi @ghuser thanks for the suggestion! Sorry for the delay on the response. If you are still interested, I do have a question on the use-case: given if you have the template in locals object, can you give an example of the code for how you intend to add the additional script?

@ghuser
Copy link
Author

ghuser commented Mar 18, 2021

Like this:

template(locals, callback){
     const $ = require('cheerio').load(locals.template);
     $('head').append(`<script>console.log('hello from injected script')</script>`)
    // I don't know what error should be (function or value) so I leave it `undefined`
    callback(undefined,  $.html());
} 

@melissawood123

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants