Latest news, food, business, travel, sport, Tips and Tricks...

Blogger b:with Tag

The <b:with> is a variable alias tag that allows us to create a complex expression that can be retrieved from child nodes.

<b:with> Syntax and Attribute

BLOGGER XML LANGUAGE

<b:with value='EXPRESSION'

        var='STRING'>

 

</b:with>

Several <b:with> tags can be nested.

EXPRESSION result must be a Singleton in direct data: call.

Child can retrieve its data result with tag <data:STRING/> where the STRING is the variable name.

<b:with> Examples

WITH STRING

<b:with value='"Type Food"' var='type'>

<b:with value='["Meat","Fruit","Vegetable"]' var='Food'>

    <data:type/>

    <ul>

    <b:loop values='data:Food' var='loop'>

        <li><data:loop/></li>

    </b:loop>

    </ul>

</b:with>

</b:with>

RESULT:

Type of Food

  - Fruit

  - Meat

  - Vegetable

<data:type/> can be executed immediately since its only contain single string. Since <b:with> printed result can only take singleton, data:food must be given to another tag, in this example <b:loop> tag to print its result with <data:loop/>.

CREATING DATA OBJECT

<b:with value='{ Name: "Foo", Gender: "Male" }' var='OBJ1'>

<b:with value='{ Name: "Bar", Gender: "Female" }' var='OBJ2'>

<b:with value='{ foo: data:OBJ1, bar: data:OBJ2, baz: "unknown" }' var='OBJECT'>

  <ol>

    <li>Name: <data:OBJECT.foo.Name/> | Gender: <data:OBJECT.foo.Gender/></li>

    <li>Name: <data:OBJECT.bar.Name/> | Gender: <data:OBJECT.bar.Gender/></li>

    <li>Name: <data:OBJECT.baz/></li>

  </ol>

</b:with>

</b:with>

</b:with>

RESULT:

1. Name: Foo | Gender: Male

2. Name: Bar | Gender: Female

3. Name: Unknown

In this example we create an object node, the main object is variable with name 'OBJECT', it has three nodes: foo, bar, and baz. foo and bar is not a string, so we don't need quote sign for them. We cannot call <data:OBJ1/> or <data:OBJ2/> because of he has multiple data. Where baz has only single data, we can describe <data:OBJECT.baz/>. foo contain data from OBJ1 and bar has data from OBJ2, later on become his own nodes.

RESIZE AN IMAGE

<b:with value='data:post.featuredImage.isResizable ? resizeImage(data:post.featuredImage, 72, "1:1") : data:post.thumbnail' var='image'>

    <img alt='' border='0' expr:src='data:image'/>

</b:with>

If featured image is resizeable, resizeImage will play, otherwise data:post.thumbnail will be used as result of data:image.

Other Tag

,