Closed tmtmtmtm closed 1 year ago
oh yeah, looks like a bug in the docs
wtf(wiki, {
should probably be wtf.extend({
the rest of that example looks good to me.
will fix the readme this week.
cheers
fixed the readme example thanks
@spencermountain I'm afraid I'm even more confused now! I thought this section was about what should happen when the parser encounters any unknown template: i.e. in the example at https://runkit.com/tmtmtmtm/6458a3a86332d60008a93ee1 office1 would become 'handled', and both office2 and office3 would become '[unsupported template]'.
Have I completely misunderstood what this is about? Or what should I change in the notebook code to make that happen?
here's an update that works https://runkit.com/spencermountain/645ead27cc10ea0008a3b575 cheers
@spencermountain Aha! Thanks — that's very helpful and sent me in the right direction. I had been thinking this was something that would be configured in advance, like the wtf.extend
example.
It might be worth giving an example here of how to use this with wtf.fetch
as I needed to do a bit more spelunking to work how to do actually do this in that scenario. I ended up having to change:
wtf.fetch(pages, 'en', function(err, docList) {
to
wtf.fetch(pages, {
lang: 'en',
templateFallbackFn: (tmpl, list, parse) => {
let obj = parse(tmpl)
list.push(obj)
return `[unsupported template: ${tmpl}]`
}
}, function(err, docList) {
This feels a little clunky, so I'm not sure if there's a better approach.
The Adding new templates section of the docs provide sample code that I can use to handle unknown templates.
However, I can't work out how to actually get that to work. My reading of the docs suggest I should be able to do something like:
But when I run that, it complains that
wiki
is not defined, and I can't see elsewhere what that should be, or where this should live instead.