4

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"'){...}

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.