如何在 NPM 模块中呈现自定义视图?

How to render a custom view in a NPM module?

由于pushAsset不允许加载外部资源,我想渲染这个template/script我的NPM模块:

views/tag.html

<script async src="https://www.googletagmanager.com/gtag/js?id={{ data.gid }}"></script>

NPM 模块与项目级模块有点不同,因为我不能直接编辑项目文件。

Apostrophe 提供 helper functions for Nunjucks. Some of them – like addAfterContextMenu – 可以用作挂钩,将 NPM 模块的模板插入到其他模板中。

这些 钩子 apos.pages 中声明。用法:

self.apos.pages.startHead(function(req) {
  return self.partial('templateName', { gid: 'UA-123456-1' });
});

startHead 可能是一个钩子,将 partial 插入到 outerLayoutBasestartHead 块中。目前,Apostrophe 没有为 NPM 模块作者提供很多钩子。但这是 subject to change.