首页 > 解决方案 > EJS 部分/组件

问题描述

如果我有以下目录结构,是否可以在部分中渲染部分,基本上就像创建一个与反应组件没有不同的视图设置(这就是我的看法)

- server
  - views
    - partials
      - components
          component-1.ejs
          component-2.ejs
      blog.ejs
      navbar.ejs
      footer.ejs
  home.ejs
  contact.ejs

因此,在我的主页中,我有一个部分blog.ejs,而在那个部分中,我想拥有component-1.ejs

我尝试了各种排列,但总是面临错误Error: Could not find the include file

主页.ejs

<div class="example">
  <% include partials/blog %>
</div>

博客.ejs

<div class="another-example">
  <% include components/component-1 %>
</div>

使用 EJS 可以进行这种渲染吗?

标签: javascriptnode.jsejs

解决方案


推荐阅读