Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blogger's conditional tags into jquery code

Tags:

jquery

blogger

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"'){...}
like image 203
Simos Sigma Avatar asked Oct 15 '25 07:10

Simos Sigma


2 Answers

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);
like image 87
Taufik Nurrohman Avatar answered Oct 18 '25 08:10

Taufik Nurrohman


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

like image 28
Prayag Verma Avatar answered Oct 18 '25 07:10

Prayag Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!