Recently Blogger has released several new operators for the syntax of XML them. This new syntax allows us to be able to write code templates that better, more logical and more efficient. In addition to reducing the size of the file is XML, the new syntax also allows developers to be able to find new potentials in manipulating the template code Bloggers who used mostly only we can do with JavaScript. Here is a summary ...
And
Before
<b:if cond='data:blog.searchQuery'>
<b:if cond='data:numPosts > 10'>
The search results by the number of posts more than 10 ...
</b:if>
</b:if>
After
<b:if cond='data:blog.searchQuery and data:numPosts > 10'>
The search results by the number of posts more than 10 ...
</b:if>
<b:if cond='data:blog.searchQuery && data:numPosts > 10'>
The search results by the number of posts more than 10 ...
</b:if>
Or
Before
<b:if cond='data:blog.pageType == "index"'>
Pass the test ...
</b:if>
<b:if cond='data:blog.pageType == "item"'>
Pass the test ...
</b:if>
After
<b:if cond='data:blog.pageType == "index" or data:blog.pageType == "item"'>
Pass the test ...
</b:if>
<b:if cond='data:blog.pageType == "index" || data:blog.pageType == "item"'>
Pass the test ...
</b:if>
Not
Before
<b:if cond='data:comment.isDeleted'>
<b:else/>
Comments are not erased here ...
</b:if>
<b:if cond='data:comment.isDeleted == "false"'>
Comments are not erased here ...
</b:if>
After
<b:if cond='!data:comment.isDeleted'>
Comments are not erased here ...
</b:if>
<b:if cond='not data:comment.isDeleted'>
Comments are not erased here ...
</b:if>
Which can not be:<!-- TEMPLATE ERROR: 'not' term cannot be used as operator except when preceding 'in' or 'contains' -->
<b:if cond='data:comment.isDeleted not "false"'>
Comments are not erased here ...
</b:if>
<!-- TEMPLATE ERROR: Extra characters at end of string: buf=[!] remainder=["false"] -->
<b:if cond='data:comment.isDeleted ! "false"'>
Comments are not erased here ...
</b:if>
Which can be:<b:if cond='not data:comment.isDeleted == "false"'>
Comments are not erased here ...
</b:if>
<b:if cond='!data:comment.isDeleted == "false"'>
Comments are not erased here ...
</b:if>
Ternary Selector
Before
<html class='<b:if cond='data:blog.pageType == "item"'>
page-item
<b:else/>
page-non-item
</b:if>'>
…
</html>
After
<html expr:class='data.blog.pageType == "item" ? "page-item" : "page-non-item"'>
…
</html>
<html expr:class='"page-" + (data.blog.pageType == "item" ? "" : "non-") + "item"'>
…
</html>
Membership
Almost the same as the operatoror, just that all references must be the same comparison, values are distinguished:
Before
<b:if cond='data:comment.author == "Taufik Nurrohman"'>
Admin comment ...
</b:if>
<b:if cond='data:comment.author == "Taufik"'>
Admin comment ...
</b:if>
<b:if cond='data:comment.author == "Admin"'>
Admin comment ...
</b:if>
After
<b:if cond='data:comment.author in {"Taufik Nurrohman","Taufik","Admin"}'>
Admin comment ...
</b:if>
<b:if cond='data:comment.author in ["Taufik Nurrohman","Taufik","Admin"]'>
Admin comment ...
</b:if>
<b:if cond='{"Taufik Nurrohman","Taufik","Admin"} contains data:comment.author'>
Admin comment ...
</b:if>
<b:if cond='["Taufik Nurrohman","Taufik","Admin"] contains data:comment.author'>
Admin comment ...
</b:if>
Else If
Before
<b:if cond='data:blog.pageType == "item"'>
<data:post.body/>
<b:else/>
<b:if cond='data:blog.pageType == "static_page"'>
<data:post.body/>
<b:else/>
<data:post.snippet/>
</b:if>
</b:if>
After
<b:if cond='data:blog.pageType == "item"'>
<data:post.body/>
<b:elseif cond='data:blog.pageType == "static_page"'>
<data:post.body/>
<b:else/>
<data:post.snippet/>
</b:if>
or…<b:if cond='data:blog.pageType in {"item","static_page"}'>
<data:post.body/>
<b:else/>
<data:post.snippet/>
</b:if>
Comments
Post a Comment