我正在使用Jekyll作为我的博客,我希望能够在特定帖子中使用独特的CSS样式.现在,我正在YAML前端中指定一个CSS文件,如下所示:
style: artdirection.css
Run Code Online (Sandbox Code Playgroud)
并在布局中使用它像这样:
{% if page.style %}
<link rel="stylesheet" href="{{ page.style }}">
{% endif %}`
Run Code Online (Sandbox Code Playgroud)
这有效,但我更喜欢在页面的frontmatter中的样式标记中包含实际的CSS样式,而不是链接到样式表.
我试过用两种方法处理这个问题,包括这里描述的方法,但是我捕获的变量只能在帖子本身内部使用,而不能在布局中使用.
那么,有可能吗?
我觉得真的很蠢,但我无法弄清楚这一点.我正在尝试Handlebars.js,但我不能让它显示来自Twitter API的数据.这是我得到的:
$.ajax({
url : 'http://twitter.com/statuses/user_timeline/alexlande.json',
dataType : 'jsonp',
success : function( tweets ) {
var source = $('#tweet-template').html();
var template = Handlebars.compile(source);
var context = tweets;
$('#container').html(template(context));
}
});
Run Code Online (Sandbox Code Playgroud)
这不会在我的模板中显示任何内容,但以下代码按预期工作:
var source = $('#tweet-template').html();
var template = Handlebars.compile(source);
var context = { tweets : [
{ text : "This is a test tweet" },
{ text : "And this is yet another" },
{ text : "And you always need three test tweets, right?" }
]};
$('#container').html(template(context));
Run Code Online (Sandbox Code Playgroud)
这很简单,我不理解,对吧?