b:get

<b:get>...</b:get>

Gets content from a datamodel.

<b:get> is used to display data from any data model inside a page. After defining data model, name and possibly narrowing the result down with parent and where attributes, b:get lists the found results, displaying html and executing scripts inside of it as many times as there are results.

You can choose what content to display by placing a field name tag or by using PHP API function B::getField() inside the <b:get> tag.

To show and execute something before and after the results, you can use <b:before> and <b:after> tags. When no data is received, content inside the <b:nodata> tag will be shown and executed.

You can use <b:get.recursion /> to get new entries in a place where the tag is. This will execute the same <b:get> with different parent or where clause as long as there are some results found. Recursion is useful if you're creating for example a structured list of contents.

To get information of the received results like the result count or to test if the data in this loop is first or last record, you can use <b:get.resultdata/>.

b:get tags

b:get.field

<b:get.field />
Displays received content from b:get.

b:get.metadata

<b:get.metadata />
Displays received content's metadata from b:get.

b:get.recursion

<b:get.recursion />
Runs again with different parent and/or where clause.

b:get.resultdata

<b:get.resultdata.field />
Displays data about received result and the search.

b:before

<b:before>...</b:before>
Show content before the getdata results

b:after

<b:after>...<b:/afterdata>
Show content after the getdata results

b:data

<b:data>...</b:data>
Shows content with each result

b:nodata

<b:nodata>...</b:nodata>
Show content if there's no results

Attributes

from

Name of the data model from which the data is to be received.

Please note that this is the database name of the data model which can be found in the Bildy editor from Data models navigator next to human readable names, or when you edit the data model, on the right side of the screen in properties.

name

What variable name to use inside the tag to refer to result. You can use the same name only once on a page, and the name cannot be any of the reserved names.

offset

(optional)
How many results to jump over from the begin. Offset is often used together with limit to create pagination.

amount

(optional)

Limits amount of received entries. Default is not limited.

limit

(optional)

Alias for amount.

orderby

(optional)

Orders received entries by this field. Default is metadata.position.

Fields that you can order by are any of the fields in your data model and also:

  • metadata.url
  • metadata.name
  • metadata.parent
  • metadata.position (same order as in Bildy editor)
  • metadata.modified
  • metadata.created

You can alter the direction of ordering with the attribute direction.

direction

(optional)

Defines ordering direction.

Valid values are asc (ascending) and desc (descending). Default is ascending.

where

(optional)

If given, indicates the condition or conditions that rows must satisfy to be selected.

In the where clause, you can use any of the functions and operators that MySQL supports, except for aggregate (summary) functions. See MySQL documentation Chapter 11, Functions and Operators.

Please note that if there is no where or parent attributes defined, everything in the data model will be shown.

parent

(optional)

Retrives only pages that share the given parent url relative to the site root. Absolute urls (http://www.mydomain.com/mysite/product/cheese) won't work, because Bildy stores url information starting from the site root (/product/cheese). See example 3

If you want to list all the pages and sub pages under the given parent, you can use the wildcard-symbol at the end of the path. See example 4

Tip: You can use paths received from <b:page.metadata.path/> or <b:page.metadata.parent/> as parent.

nocache

(optional)

If this attribute is defined, the <b:get> will not be cached and the query will be executed on each page view.

Examples

Example 1 - Simple listing

This retrieves all the news found from the site and makes a list of them that shows news' topic, publishing date and creates a link to it's URL.

<h3>News</h3>
<ul>
	<b:get from="news_article" name="news">
		<li>
			<a href="<b:news.metadata.url />" >
				<b:news.topic />
			</a> (<b:news.metadata.created />)
		</li>
	</b:get>
</ul>

Example 2 - listing with before, after and no-data

This creates a table of car's make, model and speed.

If any data is available, <b:get> outputs the starting of a html table, then all the data and finally the ending of the table.

If no data is available, it will output a message "No car data available".

<b:get from="cars" name="car">
	<b:before>
		<table>
			<tr>
				<th>Make</th>
				<th>Model</th>
				<th>Speed</th>
			</tr>
	</b:before>
	<b:data>
			<tr>
				<td>
					<a href="<b:car.metadata.url/>">
						<b:car.make/>
					</a>
				</td>
				<td><b:car.model/></td>
				<td><b:car.speed/></td>
			</tr>
	</b:data>
	<b:after>
		</table>
	</b:after>
	<b:nodata>No car data available</b:nodata>
</b:get>

Example 3 - Using parent

This lists only those news items that are found under this page

<b:get from="news" name="news" parent="<b:page.metadata.path/>" 
				orderby="metadata.created" direction="desc">
	<b:before>
		<h2>Latest news</h2>
		<ul>
	</b:before>
	<b:data>
		<li>
			<h3>
				<a href="<b:news.metadata.url />">
					<b:news.topic/>
				</a>
			</h3>
			<div class="date">
				<b:format.date format="USA">
					<b:news.metadata.created />
				</b:format.date>
			</div>
		</li>
	</b:data>
	<b:after>
		</ul>
	</b:after>
	<b:nodata>No news found</b:nodata>
</b:get>

Example 4 - Using wildcards in parent

This lists all the news items that are found under the "media" page. This is useful if you have news in different categories, for example you have press releases, news, events, financial results etc.

<b:get from="news" name="news" parent="/media%" 
				orderby="metadata.created" direction="desc">
	<b:before>
		<h2>This just in</h2>
		<ul>
	</b:before>
	<li>
		<h3>
			<a href="<b:news.metadata.url />">
				<b:news.topic/>
			</a> (<b:get.metadata.name from="<b:news.metadata.parent/>"/>)
		</h3>
	</li>
	<b:after>
		</ul>
	</b:after>
	<b:nodata>No news found</b:nodata>
</b:get>