ejs include 하는 법

송유나·2020년 12월 24일
2

구글 검색해서 따라하는데도 안되길래 왜 그런가 한참 찾았더니 버전 문제였다.
현재 구글에 있는 대부분의 방법은 ejs 2.x버전에서 사용가능

3.x버전부터는 방법이 바뀌었다고 한다.

내가 사용하는 버전은 3.1.5 그러므로 바뀐 방법 사용했어야 함.

<%-include('경로입력')%>

예시: <%-include('head')%>
👉난 작업 파일이랑 include할 파일이 같은 경로에 있어서 파일 이름만 입력해줬다.

간--단


  • Includes
    Includes either have to be an absolute path, or, if not, are assumed as relative to the template with the include call. For example if you are including ./views/user/show.ejs from ./views/users.ejs you would use <%- include('user/show') %>.
    Includes are inserted at runtime, so you can use variables for the path in the include call (for example <%- include(somePath) %>). Variables in your top-level data object are available to all your includes, but local variables need to be passed down.

NOTE: Include preprocessor directives (<% include user/show %>) are not supported in v3.0+.

https://www.npmjs.com/package/ejs/v/3.1.5

cntl+f : includes로 찾으면 빠릅니다.

profile
개발자를 꿈꾸는 햇병아리입니다.

0개의 댓글