EJSでヘッダやフッタをinclude

EJSでヘッダやフッタをinclude

EJSでヘッダやフッタをインクルードするには、<%- include('path/to/file') %>を使います。
例えば、header.ejsとfooter.ejsというファイルがあるとします。

index.ejsでこれを使うには、次のように記述します:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <%- include('header') %> <!-- ヘッダのインクルード -->

    <main>
        <h1>Welcome to the website!</h1>
        <!-- コンテンツ -->
    </main>

    <%- include('footer') %> <!-- フッタのインクルード -->
</body>
</html>

includeのパスは、EJSファイルの位置に基づいて適宜調整してください。