Skip to content

How to Add Custom Sections to View Tab

Steve Hannah edited this page Sep 2, 2016 · 1 revision

Table of Contents

How to Add Custom Sections to the View tab

toc

The View tab is intended to give the user a detailed view of the contents of a record. By default it shows the values of each non-empty field grouped into their appropriate field groups. It also shows the most recent 5 related records from each relationship in the record. You can also add your own sections by implementing the section__xxx method of the delegate class.

Example 1: A "Hello World" Section

We'll start by adding a simple section that simply displays "Hello World" to the user. In the delegate class for your table, add the following method: function section__hello(&$record){ return array( 'content' => 'Hello World!!!', 'class' => 'main' ); }

Now if you reload our application and click on the "View" tab for any of the records in the database, you'll notice a section labelled hello with the text Hello World!!! in it.

Let's dissect the above code so that we can better understand what is going on here.

  1. The function section__hello() defines a section named hello. If you wanted to define a section named foo you would call the function section__foo()
  2. This function returns an array with the keys content, and class.
  3. The content key points to the actual HTML content of the section. In this case it is simply the text Hello World!!!.
  4. The class key defines where the section should be displayed. It accepts values of left and main only. If it is set to left, then the section will be displayed in the left column. A value of main indicates that it should be displayed in the main column.

Customizing the Section Label

hello is a boring label, so let's add our own custom label by adding the label key to the array returned by our method: function section__hello(&$record){ return array( 'content' => 'Hello World!!!', 'class' => 'main', 'label' => 'Message of the Day' ); }

Now if you load the view tab of your application, you'll notice that the section has a heading "Message of the Day".

Customizing the Section Order

A section can also specify an order attribute to define the order in which this section should appear. It defaults to 0 which may cause the section to appear at the top of the view tab. You can push it to the bottom of the view tab by assiging a higher number to the order attribute: <code> function section__hello(&$record){ return array( 'content' => 'Hello World!!!', 'class' => 'main', 'label' => 'Message of the Day', 'order' => 10 ); }

Now if you reload the view tab you'll notice that the section has moved to the bottom of the page.