3

In my blogger template add a conditional statement. But it is not working. It is always display 'Not equal'

Home url: http://abc.blogspot.in

Page url: http://abc.blogspot.in/p/my-page-url.html

For testing purpose i had pasted the below code after '<body>' tag.

<b:if cond='data:blog.url == data:blog.homepageUrl + &quot;p/my-page-url.html&quot;'> 
<h1>Equal</h1>
<b:else/>
<h1>Not equal</h1>
</b:if>

I had printed the value of <data:blog.url/> and <data:blog.homepageUrl/>p/my-page-url.html and it is same.

updates:

<b:if cond='data:blog.url == &quot;http://abc.blogspot.in/p/my-page-url.html&quot;'> 
    <h1>Equal</h1>
    <b:else/>
    <h1>Not equal</h1>
    </b:if>

//Not equal

<b:if cond='data:blog.url == &quot;http://abc.blogspot.com/p/my-page-url.html&quot;'> 
    <h1>Equal</h1>
    <b:else/>
    <h1>Not equal</h1>
    </b:if>

//Equal

Thank You

3 Answers 3

4

Replace the above code with this

<b:if cond='data:blog.pageId == "PAGE_ID"'>
    <h1>Equal</h1>
    <b:else/>
    <h1>Not equal</h1>
    </b:if>

To find the PAGE_ID go to Pages, now click edit to open the page in Blogger post editor. In the address bar you may find something like this "pageID=6284317258827606063" now copy the page id and replace with the PAGE_ID above.

4
  • Sorry! Still it is 'Not equal'. Any idea with 'contains'. I had tried <b:if cond='data:blog.url contains &quot;p/my-page-url&quot;'> <h1>contains</h1> <b:else/> <h1>not contains</h1> </b:if>
    – Pamba
    Jun 21, 2017 at 2:16
  • @user2214646 sorry...i updated the answer... please check that Jun 21, 2017 at 2:17
  • using page id is the simplest way to achieve what you want... let me know if that works for you @user2214646 Jun 21, 2017 at 2:23
  • PAGE_ID logic is working fine. Thank you very much :)
    – Pamba
    Jun 21, 2017 at 2:23
1

Replace the '+' with 'path' without '.

0
0

Patternpy answer is correct. You can use this to achieve what you want.

<b:if cond='data:blog.url.canonical== data:blog.homepageUrl.canonical path "my-page-url.html"'>
    <h1>Equal</h1>
    <b:else/>
    <h1>Not equal</h1>
</b:if>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.