The range operator is used to control the output result as a shorthand way to set up arrays. When used with arrays, the range operator simplifies the process of creating arrays with contiguous sequences of numbers.

Range operator can be used only in operator that has table view, mostly used in blogger inside <b:loop> tag. There is three operator, [limit], [offset] and [to].

Not like the other two, the operator [to] can only be used in <b:loop> tag, and he cannot be associated with other operator or combined with other operator in the expression. We can say he is loner and must be alone.

Blogger Range Operator List

Operator Meaning Default syntax
limit Limit the output by x * number array take number
take array limit number
Skip Skip x* number of the output array skip number
offset array offset number
to Define number x* to x* number to number


Blogger Range Operator [LIMIT] aka [TAKE]

The operators take or limit allow us define a maximum limit table view sets of an array.
Example with String dataset
<b:loop values='["foo","bar","baz"] limit 2' var='item'>
  <data:item/>
</b:loop>
The table contains 3 entries, because we give a limit statement, the output will only show "Foo" and "Bar".
Example with data:posts
<b:loop values='data:posts limit 2' var='item'>
  <a expr:href='data:post.url'><data:post.title/></a>
</b:loop>
The result will display the first two Post Titles with their URL of the post.


Blogger Range Operator [OFFSET] aka [SKIP]

Operators skip or offset will give a statement to start the display from the specified statement.
Example with String dataset
<b:loop values='["foo","bar","baz"] offset 2' var='item'>
  <data:item/>
</b:loop>
In the 3 entries above, the first 2 will be ignored or skipped, so only "baz" will be displayed.
Example with blogger data
<b:loop values='data:posts skip 2' var='item'>
  <a expr:href='data:post.url'><data:post.title/></a>
</b:loop>
If there is 7 post, the post title along with their URL starting from 3rd post will be displayed.

Blogger Range operator [TO]

This operator to creates an array of numbers form x* to x*, and only accept number as operand.
Example Creating Range
<b:loop values='3 to 5' var='item'>
  <data:item/>
</b:loop>
The result of the operation is range number 3 to 5 which is 3, 4 and 5.
As stated above, this operator is a loner. Lets say, from the 7 post set as maximum number post set in the Blog 1 Widget Settings, we want to take only post 3, 4 and 5.  We cannot write like the other two operators, which we can inject on the tail 'data:post 3 to 5'. See the workaround from the example below 
Example to take only post 3, 4 and 5
<b:loop values='2 to 4' var='range'>
<b:loop index='number' values='data:posts' var='post'>
  <b:if cond='data:number == data:range'>
    <a expr:href='data:post.url'><data:post.title/></a>
  </b:if>
</b:loop>
</b:loop>
In the first loop we create an array number 2, 3 and 4. In the second loop with variable named 'post', we give index to the loop which named 'number' this will give number of each output of the loop starting from 0. Lets say we have 7 post in the loop, so the number is 0 ~ 6.

Now in the <b:if> tag, we give a condition if 'number' equal to 'range'. The 3rd post have the index number 2, which is equal to range 2, since condition is fulfilled so data:post.title of the third post aka our post title along with the URL that hold in the loop with variable name 'post' will be released and displayed, as well as 4th and 5th of the post.

Other operators

Share This

About
BloggerBasics101 is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
Misc
Course