在 Apostrophe CMS / Nunjucks 中显示单个图像

Display a single image in Apostrophe CMS / Nunjucks

即将出现非常简单的问题!

所以,我要做的只是最基本的 HTML:

<img src="myfile.jpg">

但我面临两个问题:

1) 当我使用上面的方法时,我得到

"TypeError: Cannot read property '_id' of null"

...接着是很多错误,然后是

"^^^^^ LOOK UP HERE FOR THE LOCATION WITHIN YOUR HELPER e.stack: Template render error: (apostrophe-pages:notFound.html) Template render error: (apostrophe-pages:notFound.html)"

...后面还有很多错误

2) 我不知道将图像存储在哪个目录中(它应该在模块目录中吗?)。我不想将它存储在主 'image library'

大概需要某种形式的 Nunjucks 编码?

谢谢!

你不会因为在常规旧 HTML 中有一个损坏的 src 而得到那个错误。也许粘贴完整的错误或注释掉一些最近添加的代码以推断出该错误。

为了回答您的问题,Apostrophe 使 /public 目录可用作根目录,因此如果您将图像文件放在 /public/images/myfile.jpg 中,您应该能够从 <img src="/images/myfile.jpg" /> 在你的模板中。