Defines the template for each repetition of the repeater. Access the datasource content through the variable named in the as attribute to render the content in the datasource.
Attributes
- `as`
string
The name of the variable to be registered for each row. For example, as="myvar" will let you reference $myvar inside the control.
An array of fields to group by, if datasource is a function that supports a Query Array.
- `dataJoins`
array
Array of tables to join with, if datasource is a function that supports a Query Array.
- `dataLimit`
int
The maximum number of results to return, if datasource is a function that supports a Query Array.
- `dataOrder`
array
Sets the order by which the data is sorted
The parameter is a two-dimensional array consisting of column names and the direction of the order.
For example, the following would sort contacts by their last name ascending and in the event of two contacts having the same last name, their first name descending
Sets whether the DataSource supports the order parameter.
When set to true, an order parameter will be appended to the data. The order parameter is an array containing values similar to: [['contact_id', 'desc'], ...].
- `dataSourceSupportsPaging`
bool
Sets whether the DataSource supports the paging parameters.
When set to true, two parameters will be appended to the call to the DataSource which represent the start and limit values of pagination.
- `dataStart`
int
The number of results to skip, if datasource is a function that supports a Query Array.
- `emptyMessage`
string
The message shown when there are no rows in the data control.
- `exportable`
bool|string
If true, an 'Export Data' link will appear beneath the control which will save a CSV file to the client of all the data in the control. Default = false.
- `height`
string
Height
Sets the height of the element. The default units are pixels. include the percentage symbol % to user percentage values.
- `id`
string
Give this control a unique id. Can be accessed in the client DOM (eg, document.getElementById('myid') or in the server DOM using [? $myid ?] or [? $('myid') ?]).
- `keyAs`
string
The name of the variable to be registered for each row's key.
For arrays of entities from the database (for example getAll()), the keys will be incrementing integers starting at 0.
- `paging`
bool
Whether to enable paging for this control. With paging enabled, the initial number of results will be limited to the value of pagingrows, and a 'Show More' button will appear.
Each click of the button will append pagingrows more rows. Default = false.
- `pagingRows`
int
Use in conjunction with paging, to control the initial number of rows to be shown, and the number of rows loaded when 'Show More' is clicked. Default = 25.
- `populateAt`
string
Sets when to populate from the datasource. Not required for most tasks, but can resolve timing issues on very complicated pages.
Default = 'init'. Other possible values: 'render'.
- `styleRow`
string
The inline style for rows (<tr> tags).
- `width`
string
Width
Sets the width of the element. The default units are pixels. include the percentage symbol % to user percentage values.
- `onPopulateServer`
callable
Called after the data control has populated from the datasource / component
Tutorials
Dynamic navigation which is populated with post articles.
This article explains how to create dynamic navigation which is automatically populated by post articles. This can be useful for creating
small sidebar menus of recent posts, or footer navigation which lists post article titles.
How it Works
The navigation will be populated with the titles of all post articles of a certain post category. The <data:repeater> will be used
to retrieve the post articles, with the data source being set to a call to the Oncord API.
The <data:repeater> is similar to a for loop which will repeat everything inside the tag until there are no more items left to
return from a data source.
The data repeater specified above uses the following attributes, for a list of all attributes please see the APIhere.
as="post" - This attribute determines the name of the variable to be registered for the repeating element. In
this case the variable has been given the name "post" and is therefore referenced as $post.
datalimit="4" - This attribute defines the maximum number of rows the data repeater will return. In this case it
was decided that there needed to be a maximum of four articles displayed.
datasource="\Components\Website\Posts::getAllForCategory(1)" -
This attribute defines the data source of the repeater. In this example all articles where the category id=1
will be returned. To find a post category id navigate to the post categories page of the dashboard, then click a category to open the
category edit page. On this page there is a tab labelled "Developer Info", which lists the post category ID.
To implement this feature, you can simply add the attribute paging="true" to a <data:repeater> tag, and pagingrows="5"
to control the number of elements to display before displaying the "Show More" button.
An Example: Posts
The following code is used to display a list of Posts associated with a Post Category:
The data repeater specified above uses the following attributes, for a list of all attributes please see the APIhere;
as="post" - This attribute determines the name of the variable to be registered for the repeating element. In this case the variable has been given the name "post" and is therefore referenced as $post.
datalimit="4" - This attribute defines the maximum number of rows the data repeater will return. In this case it was decided that there was no need to have a maximum number of posts, so it was left out.
datasource="\Components\Website\Posts::getAllForCategory(1)" - This attribute defines the data source of the repeater. In this example all articles where the post category id=1 will be returned. To find a post category id, navigate to the post categories page of the dashboard, and then click a category to open the category edit page. On this page there is a tab labelled "Developer Info", which lists the post category ID.
paging="true" - This attribute enables the "Show More" paging feature.
pagingrows="5" - This attribute defines the number of rows to display before displaying the "Show More" button.
Oncord's UI Controls API includes a pre-built rotator, which helps reduce development time, while providing users with an
improved experience updating content via the visual editor.
Some notable features of the Oncord rotator:
May be placed and configured via the visual page editor.
Supports html content and other Oncord UI controls such as sections, not just images.
Supports YouTube videos, where videos are stopped between slides.
Customize the rotator controls with your own images or icons.
Supports responsive content.
Customize the transition time and effect to be used between slides (slide or fade).
Show multiple content items per slide (eg. 4 testimonials per slide).
Introducing The Rotator UI Control
You can add a rotator to a website page or design through use of the <layout:rotator> UI Control.
Alternatively, a rotator can be added to the page via the visual editor. Click "Insert" on the left-hand side of the screen while
editing a website page, and drag-and-drop a "Rotator" element into position on the page.
In order to take advantage of all the features and possibilities of the rotator UI control, take note of all the "Attributes"
available in the API reference here.
The <layout:rotator> control can handle any standard content. Each direct child of the rotator will be turned into its own slide.
The rotator includes standard next / previous controls, however you can alternatively add custom links instead.
Place your custom navigation elements within links that are assigned with unique IDs.
Add the attributes moveNextId and movePreviousId to the <layout:rotator> control, where the IDs that you provide correlate
to the IDs used by your next / previous buttons.
Set the attributes arrowVariant="none" minimapVariant="none", to remove Oncord's default rotator navigation elements.
Logic is used to show content based on a test. Repeaters are used to list elements like Products, Pages, or Contacts.
Logic IF
The <logic:if> control performs a test, and renders everything inside the tag if the test is true. The test
is defined within the test="true" attribute, and is often an API call.
The following examples are usually defined in the website design to show content dynamically:
IF the current visitor is logged in, show "you are logged in".
<logic:if test="\Components\Customers\Contacts::currentIsLoggedIn()">
<p>You are logged in.</p>
</logic:if>
IF the current page is the "About Us" page, show a heading.
The <logic:else> control defines an alternate region to show in the case that an IF test fails. Extending the
above examples:
IF the current visitor is logged in, show "you are logged in". ELSE show "You are not logged in":
<logic:if test="\Components\Customers\Contacts::currentIsLoggedIn()">
<p>You are logged in.</p>
</logic:if>
<logic:else>
<p>You are not logged in.</p>
</logic:else>
IF the current page is the "About Us" page, show a heading. ELSE show a message "Another Page".
<data:repeater> is commonly used to list elements like Products, Pages, or Contacts.
The Data Repeater repeats everything inside the tag, for each item in a given data source.
The "as" attribute defines the name of the variable, and the "datasource" attribute usually defines an API call to
retrieve a Page, Product or Contact.
The DataStart attributes may be used in addition to the DataLimit attribute to show from a record, to a record. As an example, the
following code will only show all Posts, starting at the Third Post:
You can link the data repeater to components within the system to iterate over data. Refer to the documentation of the component for function calls and field names.
Allows you to show from a record, to a record. Behaves like the LIMIT clause in SQL.
HTML:
<h1>Show the First Post</h1>
<data:repeater datasource="\Components\Website\Posts::getAll()" as="post" datalimit="1">
[? $post['post_title'] ?]
</data:repeater>
<h1>Show the First Three Posts</h1>
<data:repeater datasource="\Components\Website\Posts::getAll()" as="post" datalimit="3">
[? $post['post_title'] ?]
</data:repeater>
<h1>Show the Second and Third Post</h1>
<data:repeater datasource="\Components\Website\Posts::getAll()" as="post" datastart="1" datalimit="2">
[? $post['post_title'] ?]
</data:repeater>
<br /><br />
datastart="1" datalimit="2" behaves the same as SQL's LIMIT 1 2
DataFilter Attribute
Allows you to specify conditions in your query. Behaves like the WHERE clause in SQL.
HTML:
<h1>Returns all products greater than $100 in value</h1>
<data:repeater datasource="\Components\Commerce\Products::getAll()" as="product" datafilter="[? [['product_price_base', '>', 100]] ?]">
[? $product['product_title'] ?]
</data:repeater>
DataOrder Attribute
Allows you to specify conditions in your query. Behaves like the ORDER clause in SQL.
The getDataCount() method returns the number of data items in the Repeater's dataset. This example demonstrates how to use getDataCount() to conditionally show a repeater when it has 1 or more results. This can be used as a more flexible alternative to the EmptyMessage attribute as it can be used to target any number of results.
HTML:
<!-- Use getDataCount() to conditionally show the repeater if it has 1 or more results -->
<logic:if test="$related_products_repeater.getDataCount()" evaluateat="render">
<data:repeater id="related_products_repeater" as="product" datasource="\Components\Commerce\Products::getAllForCategoryAndBrandRecursive($arrCategoryIds,null)" datalimit="[? $datalimit ?]" datafilter="[? $datafilter ?]">
[ template code here ]
</data:repeater>
</logic:if>