What are database templates?
    • 01 Nov 2022
    • 4 minutes to read

    What are database templates?


    Article Summary

    Setting up database templates is part of the process of setting up a database activity

    Once you have created the fields for your database, you probably want to edit the templates that define the user interface. Creating the fields produces a default template.

    Database templates all work on the same principle. They are basically HTML pages with a new set of tags for the database module to interpret. When editing a template, Totara displays a list of available tags on the left side of the editing screen. Double-clicking on any of the tags adds it to the template. The database activity interprets these new tags before sending the template’s HTML to the browser for display. It looks for words enclosed in either two square brackets ([[) or two hash signs (##), representing two different types of interface elements it can add to the template.

    The square brackets define data tags, which tell the module to replace the word in the brackets with the value or form element of the field with the same name. So if you have a database with a name field, you would represent it in the template with [[name]]. In the single or list template, the module would replace it with the data in the name field for that entry. In the list template, the module would replace it with a text field, and put the value in the text field if you’re editing the entry instead of creating a new one.

    The ## tags indicate the word should be replaced by an icon or link for interacting with the module. These tags are used to place the edit and delete icons, and links for More, Approve, Comments, and User. If you want to add the edit icon to a template, you just add a tag that looks like ##edit##. When the user looks at the page with the tag, the database module replaces it with the edit icon. If the user then clicks on the icon, it takes them to the edit template.

    Aside from the replacement tags, creating a template is just like creating an HTML page. Use a table to lay out the data elements (this is an acceptable use of tables for layout), add descriptive text around the replacement tags, and publish. The database makes it easy to rapidly view your changes by flipping between the Templates tab and the tab for the template you are working on.

    There are three basic templates necessary to use the database; list, single, and add. The three other templates; RSS, CSS, and JavaScript are more advanced templates and aren’t necessary for basic database use. Find out more about the template types below, or find out how to edit a database template.

    Single template

    The single template is the detailed view of an entry. This template should list all of the available data. Consider organising the data if you have a lot of fields in your database.

    List template

    The list template is the first page learners will see when they come to your database. The list template should give an overview of the entries and enable users to click through to the single or edit template.

    Organising a good list template is a bit of a challenge. First, you should identify the fields that will be most helpful to users for selecting the entries they want to view. The default layout almost always has too much information.

    The form has three areas: the Header, Body, and Footer. If you lay out the list template as a table, you’ll want to use the Header area as the table header, the Body for the data, and the Footer to close the table. But the HTML editor puts a full table in each area, which makes it difficult to get proper alignment of the elements and not repeat the headers for every entry.

    A knowledge of tables in HTML is required in order to lay out the entire list template as one table.

    To make the entire list template as one table:

    1. On the list template page, turn off the HTML editor.
    2. In the Header area of the template, open the table and add a row for your header text. Each column should contain one element of the header.
    3. In the Body, create another row with the data and command replacement tags.
    4. In the Footer, close the table.
    5. Save the template.

    Do not switch the HTML editor on while editing this template. If you turn the editor back on, it will create tables in each of the areas.

    RSS template

    The RSS template allows you to structure the RSS feed from the database. If you have enabled RSS feeds for the database in the database options, the database will publish the entries in a feed. This template allows you to structure how the entries in the feed appear to the readers.

    CSS template

    The CSS template defines the CSS styles for all of the templates in the database. If you know CSS, you can adjust the template’s fonts, spacing, colours, and other display information.

    JavaScript template

    Like the CSS template, the JavaScript template is used by the other templates. The JavaScript template allows you to add new behaviours to the templates by defining JavaScript routines that can be loaded when the template page loads. At the time of this writing, the JavaScript API isn’t yet documented, but the image gallery preset uses JavaScript to define the size of images in the list and single templates.

    C027 - Databases(1)The Database activity course in the Totara Academy contains more resources and learning materials, including best practice and the chance to give it a go yourself. 

    © Copyright 2024 Totara Learning Solutions. All rights reserved. Some content originally obtained via GPLv3 license and continues to be available under GPLv3. All other content is the sole copyright of Totara Learning Solutions. 


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.