Data Output (data:)
Examples
-
<data:title/> would print out the title of a widget
-
<data:photo.url/> - Size: <data.photo.width /> x <data.photo.height /> would print attributes of a photo component. A photo may have components such as url, height, and width. Using the "." notation indicates that we want the URL for this photo, rather than a URL from something else.
See more examples
See our complete list of the layouts data tags that are supported.
Loops (b:loop)
When to use b:loop
The b:loop tag lets you repeat a section of content multiple times. This is most commonly used for printing out each post in a list of posts for a given page, or each comment, or each label, etc.
Format
The general format for using loops is this:
<b:loop var='identifier' values='set-of-data'>
[repeated content goes here]
</b:loop>
The 'identifier' (i) part can be any name you choose, and will be used to stand in for each new item in the list, each time through the loop. The set of data you specify for the values can be any piece of data described in the data tags article as being a list of items.
For example, in the blog posts widget, posts is a list. Code like the following will loop through each post, printing out the title for each one, with header tags around it.
<b:loop var='i' values='data:posts'>
<h2><data:i.title/></h2>
</b:loop>
Notice how "i" takes on the value of each post in turn, so you can get the title from each one.
Number Range
A loop tag allows you to iterate across an inclusive number range, such as ‘1 to 3', ‘-3 to -9', where the value of the variable takes the number's value. The following example would create an unordered list of 1, 2 and 3.
<b:loop var='i' values='1 to 3'>
<li><data:i /></li>
</b:loop>
Index Attribute
Loop tags also have an optional index attribute, which gives the zero-based index of the current iteration through the loop.
<ul>
<b:loop var='number' index='index' values='9 to 7'>
<li>Index: <data:index />, Number: <data:number /></li>
</b:loop>
</ul>
This example would create an unordered list of:
- Index: 0, Number: 9
- Index: 1, Number: 8
- Index: 2, Number: 7