Br34th7aking
Br34th7aking

Reputation: 89

How to use the value of Blogger tags in custom Javascript?

I've been trying to find out the name of the author of a post using javascript and blogger tags.

The name of the author is stored in the data tag <data:post.author>.

I want to detect that name in custom javascript code I wrote.

<script type="text/javascript">
    var author = &quot;<data:post.author>&quot;;
    document.getElementById("author").innerHTML = author;
</script>

But it doesn't extract the value from it. How can I get the value of that data tag to use inside javascript?

Upvotes: 1

Views: 645

Answers (1)

Prayag Verma
Prayag Verma

Reputation: 5651

You will need to replace <data:post.author> with <data:post.author/> otherwise you will see the following error when saving theme code -

The element type "data:post.author" must be terminated by the matching end-tag "</data:post.author>"

Also, a thing to note is that, the data:post dictionary data layout tags will only work if they are added between the statement -

<b:loop values='data:posts' var='post'>
<!-- Your Code -->
</b:loop>

This b:loop is present inside the Blog widget.

If these data layout tags are used outside that b:loop statement, then they won't work because Blogger won't be able to find the dictionary of data:post (The globally available dictionaries in Blogger themes are data:blog , data:view , data:skin , data:widgets and data:messages)

Upvotes: 1

Related Questions