我正在尝试创建一个DocFx模板,使用它对小胡子的支持。
我希望能够生成一个网站菜单,在所有生成的html页面的导航栏中,基于项目根中的toc.yml文件。
我知道默认模板可以做到这一点。但它显然是通过将toc.yml转换为独立的html文件来实现的,然后由概念html文件中的javascript解析该文件以加载菜单。
我希望能够直接在moustache文件中完成这项工作,该文件创建了概念性的html文件。
我创建了这个部分(toc.tmpl.partial),并在概念小胡子文件的适当部分中调用它:
{{!版权所有(c) Microsoft。版权所有。在麻省理工学院许可下获得许可。有关完整的许可证信息,请参阅项目根目录中的许可证文件。}}
<div class="sidenav">
this is sidenav!
{{#items}}
hello!
{{/items}}
</div>但是,不幸的是,{{item}}标记中没有生成任何内容。
但是,如果我在toc.tmpl中使用相同的代码,一个包含适当数量的hello的html文件!lines被生成。
所以我遗漏了一些关于DocFx片段协同工作的基本信息。
这是我的简单的概念性文件生成器:
{{!include(/^styles/.*/)}}
{{!include(/^fonts/.*/)}}
{{!include(favicon.ico)}}
{{!include(logo.svg)}}
{{!include(search-stopwords.json)}}
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
{{>partials/head}}
<body data-spy="scroll" data-target="#affix">
{{>partials/navbar}}
<div style="position: relative; margin-top: 5px;">
<div class="toc-column" style="position: fixed;">
{{>partials/toc}}
</div>
<div style="position: fixed; left: 160px;" data-uid="{{uid}}">
{{{rawTitle}}}
{{{conceptual}}}
</div>
</div>
{{^_disableFooter}}
{{>partials/footer}}
{{/_disableFooter}}
{{>partials/scripts}}
</body>
</html>发布于 2017-06-25 23:09:00
简而言之:items是在toc的模型中,而不是在conceptual的模型中。你不会在conceptual的items中得到任何东西。您可以尝试运行docfx --exportRawModel来查看模型。
实际上,您需要使TOC的模型在所有其他文件之间共享。你可以使用isShared提到的here。将以下代码添加到toc.tmpl.js中
exports.getOptions = function (model) {
return {
isShared: true;
};
}更多信息可在此处找到:http://dotnet.github.io/docfx/tutorial/intro_template.html
https://stackoverflow.com/questions/43056774
复制相似问题