如何使用 Blogger 语法将帖子信息添加到脚本标记?
我的目标是创建一个博客小部件,将以下 JS 添加到每个帖子页面(只是博客帖子,而不是页面):
<script type='text/javascript'>
post_info = {
title: 'My Blog Post',
labels: 'this, that',
pub: '2011-07-05 18:15:52',
url: 'http://foo.blogger.com/2011/07/my-blog-post.html'
};
</script>
我想我可以使用以下代码来做到这一点:
<b:includable id='post' var='post'>
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
post_info = {
<b:if cond='data:post.title'>
title: "<data:post.title/>",
</b:if>
<b:if cond='data:post.postLabelsLabel'>
labels: "<data:post.postLabelsLabel/>",
</b:if>
<b:if cond='data:post.timestampLabel'>
pub: "<data:post.timestampLabel/>",
</b:if>
<b:if cond='data:post.url'>
url: "<data:post.url/>"
</b:if>
};
</script>
</b:if>
</b:includable>
我不仅不确定该放在哪里代码(因为我遇到了一些关于不将内容放入序言中的奇怪错误),但是当我没有收到这些错误时,我没有收到诸如 post in 'blog' 字典错误之类的东西。
我无法找到包含添加此类内容的文档,或者我是否需要使用 expr 或宏,或者需要将其放在页面上的位置(什么容器等)。任何帮助将不胜感激。谢谢。
My goal is to create a blogger widget that adds the following JS to every post page (just blog posts, not pages):
<script type='text/javascript'>
post_info = {
title: 'My Blog Post',
labels: 'this, that',
pub: '2011-07-05 18:15:52',
url: 'http://foo.blogger.com/2011/07/my-blog-post.html'
};
</script>
I was thinking I would be able to do that with the following code:
<b:includable id='post' var='post'>
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
post_info = {
<b:if cond='data:post.title'>
title: "<data:post.title/>",
</b:if>
<b:if cond='data:post.postLabelsLabel'>
labels: "<data:post.postLabelsLabel/>",
</b:if>
<b:if cond='data:post.timestampLabel'>
pub: "<data:post.timestampLabel/>",
</b:if>
<b:if cond='data:post.url'>
url: "<data:post.url/>"
</b:if>
};
</script>
</b:if>
</b:includable>
Not only am I not sure where to put the code (cause I have gotten some weird errors about not placing things in a prolog), but when I don't get those errors, I get no such thing as post in 'blog' dictionary errors.
I haven't been able to find the documentation that covers adding things like this or whether or not I need to be using expr or macros or where this would need to go on the page (what container etc). Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的帖子的一些不存在的属性:这里是可用属性的完整列表
这就是 JavaScript 的样子:
最简单的方法是将上面的代码放入 b:includable 中
id='main'
位于 b:widget 中,带有type='Blog'
。我用来学习有关博客模板的一些第三方教程:
You are using some inexistent properties of posts: Here is a full list of available properties
And this is how JavaScript should look like:
The easiest way is to put the above code in b:includable with
id='main'
which is in b:widget withtype='Blog'
.Some third party tutorials that I used to learn something about blogger templates: