Simos Sigma
Simos Sigma

Reputation: 978

Blogger's conditional tags into jquery code

Is it possible to add blogger's conditional tags into jquery code? For example how can I do something like this...

if(cond='data:blog.pageType == "item"'){...}

Upvotes: 4

Views: 144

Answers (2)

Taufik Nurrohman
Taufik Nurrohman

Reputation: 3409

Yes.

document.addEventListener("DOMContentLoaded", function() {
    if (typeof _WidgetManager !== "undefined") {
        var data = _WidgetManager._GetAllData();
        if (data.blog.pageType == "item") {
            alert('item');
        }
        if (data.view.isHomepage) {
            alert('homepage');
        }
    }
}, false);

Upvotes: 2

Prayag Verma
Prayag Verma

Reputation: 5651

As long as the code is present in the Blogger theme (Theme > Edit HTML), you can use the b:if conditional statements directly inside the <script> tags. Like for example -

<script>
  <b:if cond='data:blog.pageType == "item"'>
    <!-- Do Something specific to the post page-->
  </b:if>
</script>

Note: Don't add the CDATA section to the <script> otherwise <b:if> conditions will stop working inside the <script> tag

Upvotes: 2

Related Questions