前提・実現したいこと
引数の中に変数を出力したいのですが、エラーが出てしまいます。
引数の中には変数を設定することはできないのでしょうか。
ページにそれぞれ、変数を設定してページ判定を行い、
ページの判定にしたがって条件分岐でpathという変数の中の引数を動的に変更したいという要件です。
ページによって、リソースファイルのディレクトリが異なるため動的に引数を設定したいのです。。。
発生している問題・エラーメッセージ
Could not find matching close tag for "<%".
該当のソースコード
ejs
1<% if ( current === 'top') { %> 2 <% path = 3 { 4 img:'../../../Content/contents/brands/<%= current %>/img', 5 css:'../../../Content/contents/brands/<%= current %>/scss', 6 js:'../../../Content/contents/brands/<%= current %>/js', 7 rs:'../../../Content/contents/brands<%= current %>/', 8 crs:'/sp/Content', 9 html:'/sp/contents/brands/<%= current %>' 10 }; %> 11<% } else if ( current === 'about') { %> 12 <% path = 13 { 14 img:'/sp/Content/contents/brands/<%= current %>/about/img', 15 css:'/sp/Content/contents/brands/<%= current %>/about/scss', 16 js:'/sp/Content/contents/brands/<%= current %>/about/js', 17 rs:'/sp/Content/contents/brands/<%= current %>', 18 crs:'/sp/Content', 19 html:'/sp/contents/brands/liftage' 20 }; %> 21<% } else if ( current === 'features') { %> 22 <% path = 23 { 24 img:'/sp/Content/contents/brands/<%= current %>/features/img', 25 css:'/sp/Content/contents/brands/<%= current %>/features/scss', 26 js:'/sp/Content/contents/brands/<%= current %>/features/js', 27 rs:'/sp/Content/contents/brands/<%= current %>', 28 crs:'/sp/Content', 29 html:'/sp/contents/brands/<%= current %>' 30 }; %> 31<% } else { %> 32<% path = 33{ 34 img:'/sp/Content/contents/brands/<%= current %>/img', 35 css:'/sp/Content/contents/brands/<%= current %>/scss', 36 js:'/sp/Content/contents/brands/<%= current %>/js', 37 rs:'/sp/Content/contents/brands/<%= current %>', 38 crs:'/sp/Content', 39 html:'/sp/contents/brands/<%= current %>' 40}; %> 41<% } %>
試したこと
<%%
を試してエスケープしないようにしてみましたが、今度は変数として読み込まれなくなってしまいました。
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
HTML5
CSS3
EJS
gulp
で開発しています。
以下のように変数と値を読み込んでいます。
html
1<section class="Hero"> 2<img src="<%= path.img %>/hero.jpg" alt=""> 3</section>
ページによって、path.imgのディレクトリが異なるため動的に引数を設定したいのです。。。
何卒お力添えをいただけますと幸いです。
あなたの回答
tips
プレビュー