开发者

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 == &quot;item&quot;'>
  <script type='text/javascript'>
    post_info = {
      <b:if cond='data:post.title'>
        title: &quot;<data:post.title/>&quot;,
      </b:if>
      <b:if cond='data:post.postLabelsLabel'>
        labels: &quot;<data:post.postLabelsLabel/>&quot;,
      </b:if>
      <b:if cond='data:post.timestampLabel'>
        pub: &quot;<data:post.timestampLabel/>&quot;,
      </b:if>
      <b:if cond='data:post.url'>
        url: &quot;<data:post.url/>&quot;
      </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 == &quot;item&quot;'>
        <script type='text/javascript'>
            post_info = {
                title: &quot;<data:post.title/>&quot;,
                labels: [
                    <b:loop values='data:post.labels' var='label'>
                        &quot;<data:label.name/>&quot;
                        <b:if cond='data:label.isLast != &quot;true&quot;'>,</b:if>
                    </b:loop>
                ],
                pub: &quot;<data:post.timestamp/>&quot;,
                url: &quot;<data:post.url/>&quot;
            };
        </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: &quot;<data:post.title/>&quot;,
            labels: [
                <b:loop values='data:post.labels' var='label'>
                    &quot;<data:label.name/>&quot;
                    <b:if cond='data:label.isLast != &quot;true&quot;'>,</b:if>
                </b:loop>
            ],
            pub: &quot;<data:post.timestamp/>&quot;,
            url: &quot;<data:post.url/>&quot;
        };
    </script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜