我正在使用Middleman,我有一个布局文件,它将jQuery CDN添加到所有.html.haml
文件的底部。布局文件在渲染完所有html元素后添加jQuery CDN。
我的一个.html.haml
文件将有一个使用jQuery的附加js文件;但是,它需要首先加载jQuery CDN。
如何告诉Middleman在编译期间,为这个特定的.html.haml
文件附加js文件?我尝试在= javascript_include_tag "jsfile"
文件的底部添加.html.haml
,但它出错了,因为它需要首先加载jQuery,直到我到达布局文件的末尾才会发生。
布局文件:
!!! 5
%html{lang: 'en'}
%head
%body{class: current_page.data.body_class || 'page'}
= yield
// jQuery
= javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"
//I need to insert my js file here, but only for a specific HTML file.
P.S。另外,我需要将jQuery放在文件的底部以提高渲染效率,因此我无法将其放在head
中。
答案 0 :(得分:2)
在弄清楚对我有用之后,在这里提供我的答案:
首先,我必须通过index_options
文件中的.html.haml
设置一个标记:
---
title: My Site
index_options: target_file
---
然后,我不得不用if
语句
!!! 5
%html{lang: 'en'}
%head
%body{class: current_page.data.body_class || 'page'}
= yield
// jQuery
= javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"
//Here's the added update:
= javascript_include_tag "my_jsFile" if (current_page.data.index_options == "target_file")