14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ejs でファイル名(path)を取得したいときのメモ

Posted at

ejs でファイル名 を取得したいときのメモ。

<%= filename %>

で、ファイルパスが文字列で返ってくる

<!-- ファイル名取得 -->
<% var path = filename.split('/')[filename.split('/').length - 1].replace('.ejs','') %>

<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" type="text/css" href="css/<%= path %>.css">
  </head>
  <body>
   ................
  </body>
</html>

ejs でうまく軌道に乗りますように。

14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?