The expression evaluation tag <b:eval> is a tag for evaluating the value of an expression. <b:eval> tags can combine or modify data values using an expression then print its value.
<b:eval> Syntax and Attribute
BLOGGER XML LANGUAGE
<b:eval expr='EXPRESSION'/>
When to use an Evaluated Expression
You can use b:eval
tag to evaluate a more complicated expression than a standard data tag.
Format
<b:eval expr='[Expression]' />
Examples
- min-height:
<b:eval expr="data:newWidth * data:height / data:width" />
px;
Output a calculated relative height, based on a new width value. <b:eval expr="data:post.labels[0].url" />
Output the url of the first post label.<b:eval expr='data:post.allowComments ? "Comment" : "Comments Disabled"' />
Output “Comment” when comments are allowed, and “Comments Disabled” when they are not. Note that this expression makes use of the ternary operator.
The evaluation tag has only one attribute, which is expr:
<b:eval> Example
A CONCATENATE OPERATION
<button class='subscribe-button pill-button'>
<b:eval expr='data:messages.subscribe + " to " + data:blog.title'/>
</button>
Result will be "Subscribe to BlogTitle"
A TERNARY OPERATION
<b:eval expr='data:view.isHomepage ? data:blog.pageName : data:blog.pageTitle'/>
The result of the expression is one of two defined values.
- If Homepage: "data:blog.pageName
- Else: data:blog.pageTitle
CREATING POST SUMMARY
<b:eval expr='data:post.body snippet {length: 250, links: false, linebreaks: false, ellipsis: false}'/>
Example usage
<ul>
<li>number of title characters = <b:eval expr='data:view.title.length'/></li>
</ul>
number of title characters = xxx <b:eval expr='1 + 2'/>
HTML render result = 3 <b:eval expr='5 * 10'/>
HTML render result = 50 <b:eval expr='data:posts.length'/>
Showing number of post <b:eval expr='((10 + data:posts.length) * 2) - 15'/>
For example: data: posts.length is 1
so it has a result of 7
((10 + 1) * 2) - 15 = 7
Resize an image with an operator call
The following example emits the post title and body for each of the posts in the data:posts dictionary.
<style>
.post-thumbnail {
background-image: url(
<b:eval expr='resizeImage(data:post.featuredImage, 385).cssEscaped' />);
}
</style>
Reviews
You can use English or Indonesian