|
Simple example of PluginTrackerlist without pretty tracker |
A pretty tracker uses a template to display the item |
There are are two ways in which pretty trackers are used.
In all cases it is about displaying tracker items using a template.
Please read this Pretty Tracker HowTo first.
A pretty tracker has several moving parts that are chained together. Not all will require all the parts below but this is the whole list. In the table below R=Required, Y=Can be used, N=Not used.
Part | Used in Wiki | Used in Tracker | Description | How many? |
Tracker | R | R | The tracker is the table that holds the data | Only one. |
Tracker Fields info | R | R | the columns of the table / fields of the form | More than one |
PluginTracker | Y | Y | If used replaces the "create a new item" in the tracker function. | 1 for each input location (can be more than one) |
Tracker Input TPL | Y | N | If PluginTracker is used this can controls how the input form should look | 1 for each PluginTracker |
Output Page | Y | N | A wiki page where the single item results will show in a wiki. Usually pagename = item name (the "links to item" field of the tracker) | 1 per item |
Tracker Item | Y | Y | All trackers will have items visible in the tracker feature. For the PTW this is redundant, or only used by admins. | 1 per Item |
Page Selector Field | Y | N | Must be used to make a PTW where each item is associated with a page. | 1 per tracker |
Display template | R | N | For wiki only - when using the pageselector you need to provide an example of a PluginTrackerlist to be copied to the output page | 1 master copy per tracker) |
Tracker Wiki Output TPL | R | N | A wiki page or tpl file used by the PluginTrackerList. Controls how the output for all items is displayed in various wiki pages. | 1 per tracker, controls all items. |
Tracker Item Output TPL | Y | Y | A wiki page or tpl file used by the tracker itself. Controls how the output for all items is displayed in the trackers item view. | 1 per tracker, controls all items. |
The following graphic depicts how a pretty tracker in a wiki page works, including how you can have a template for the input page as well as the output page.
Blue objects are seen by the end user. Green objects are behind the scenes, called by the plugins of the blue objects. Red arrows are representing the time sequence: input, processing, output.
When executed the sequence in the code works like this.
1. The Input Page calls the PluginTracker, which calls the Tracker Input TPL
2. The Input Page is rendered in the browser as "pretty"
3. The End user supplies the input for the tracker's fields - in other words, fills out the form, which includes providing the name to the Page Selector that will become the title of a new wiki page.
4. The tracker item is created in the background.
5. If the tracker has an Item Display TPL, that is called to render the tracker item.
6. If a page selector exists a wiki page is created and filled with the content of the Tracker Display, which is normally just the pre-configured PluginTrackerList.
7. When the wiki page is visited, PluginTrackerlist calls up the fields from the tracker, and the Tracker Output TPL and combines them together to render the "pretty" page as seen by the end user.
The step-by-step tutorial that follows will allow you to create a pretty tracker within the trackers function. This is a recommended first step to creating a more complicated pretty tracker. In this tutorial you will display a pretty tracker item using an Item Output TPL. If you get that far, you can use the template made here as the basis for a Pretty Tracker in a Wiki Output TPL.
Note: This tutorial assumes you know how to set up a tracker.
{$f_12} Username {$f_13} City {$f_14} Photo {$f_15} Join Date {$f_16} Wants to Buy {$f_17} Wants to Sell {$f_18} GroupName
So far the tracker inputs and outputs have been rather static. It is not possible to change a field according to the value of another field, for example.
But what if you want to have different questions or different answers displayed in your template based on the information in that item? Basic conditional display is covered by PluginTrackerToggle. Using pretty trackers and JavaScript, more advanced behavior is possible for those who know HTML, DOM and JavaScript. The following form uses the jQuery library and PluginJq:
Log in as registered user to see the jquery in action in this "Dynamic tracker example".
The layout of this pretty tracker is defined in the template page Dynamic tracker example template, which also contains the code to make the form dynamic. The code below will use field numbers to control these field.
Field number | Name | |||
121 | Content type | |||
122 | File | |||
123 | URL | |||
124 | Did you ensure this does not breach policy? |
Tracker field IDs and names have changed to improve consistency: all tracker fields now use ins_XX, where XX is the fieldId.
For more information, read: http://doc.tiki.org/Tiki7#Upgrade_notes
The form contains two alternative fields which are initially hidden. When a radio button is selected, the corresponding field appears. Since none of these fields is always required, the tracker fields are not defined as mandatory. But this is emulated using a JavaScript check when submitting the form.
The initial state is achieved with the following code:
$("#fileprompt").hide(); $("#urlprompt").hide();
fileprompt and urlprompt are the identifiers of DIV elements defined in the template to allow controlling the display of the 2 fields and their label:
{DIV(type="div",id="fileprompt")} File: {$f_122} {DIV} {DIV(type="div",id="urlprompt")} URL: {$f_123} {DIV}
The following code handles selection of a radio button, showing a field and making sure the other one is hidden:
$("input[name='track_121']").change(function(){ if ($(this).filter(":checked").val() === 'File') { $("#urlprompt").hide(); $("#fileprompt").fadeIn(); } else { $("#fileprompt").hide(); $("#urlprompt").fadeIn(); } });
The function is executed when field 121 is changed. When the function is executed, one of the 2 blocks is run depending on the value of the selected (or "checked") radio button.
The user needs to fill a boolean field, but one value is not normal. A message is displayed if the user selects "No". The following code does this adding a handler to the change event on the select element:
$("select[name='track_124']").change(function(){ if ($(this).find("option:checked").attr("value") === 'No') { alert("Then go do your homework."); } });
see Pretty Tracker in a Wiki Page
Attached to this wiki page as a downloadable PDF and MS Word files.
{$f_created}: created date
{$f_status_input}: status input field (for plugin tracker with showstatus="y"
)
{$f_status}: status (output)
{$f_itemId}: the item id
{$f_lastmodif}: last modified date (this will display unix date, for human readable date look below)
(In Tiki 8 onwards) {$itemoff}: the iteration number of each item
{$tr_offset}: the offset of the item, i.e. this is the nth item of the total number of x items
You can easily integrate registration information in your pretty tracker using the proper syntax
{$register_login}
{$register_email}
{$register_pass}
{$register_pass2}
{$register_passcode}
{$register_groupchoice}
{$register_antibot}
See http://doc.tiki.org/User-Tracker#Using_Pretty_Trackers_to_generate_the_Registration_Tracker
Modifiers can be applied using "|" (pipe).
{$f_lastmodif|tiki_short_date} will display human readable date only.
{$f_lastmodif|tiki_short_datetime} will display human readable date and time.
etc...
{$f_122|output}
This is reported not to work within a wiki table
Related commit: http://sourceforge.net/p/tikiwiki/code/31403
There are certain limitations to the use of pretty tracker veriables when using a wiki page as the template, for example:
The solution in this case is to use a Smarty template file as the template rather than a wiki page.
See:
Aliases: PrettyTracker | PrettyTrackers | Pretty Trackers | Pretty+Tracker