How do I add post information to script tags with Blogger syntax?
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.
You are using some inexistent properties of posts: Here is a full list of available properties
And this is how JavaScript should look like:
<b:loop values='data:posts' var='post'>
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
post_info = {
title: "<data:post.title/>",
labels: [
<b:loop values='data:post.labels' var='label'>
"<data:label.name/>"
<b:if cond='data:label.isLast != "true"'>,</b:if>
</b:loop>
],
pub: "<data:post.timestamp/>",
url: "<data:post.url/>"
};
</script>
</b:if>
</b:loop>
The easiest way is to put the above code in b:includable with id='main'
which is in b:widget with type='Blog'
.
Some third party tutorials that I used to learn something about blogger templates:
- http://templateofdoom.synthful.org/Home
- http://thoughtsomething.blogspot.com/2009/01/understanding-blogger-template-1.html
<script type='text/javascript'>
post_info = {
title: "<data:post.title/>",
labels: [
<b:loop values='data:post.labels' var='label'>
"<data:label.name/>"
<b:if cond='data:label.isLast != "true"'>,</b:if>
</b:loop>
],
pub: "<data:post.timestamp/>",
url: "<data:post.url/>"
};
</script>
精彩评论