Cumulus template file
- 1 Introduction
- 2 Template files you add
- 2.1 Using web tags in templates for creating HTML pages
- 2.2 Using web tags in scripts
- 2.3 Inconsistency of web tag names
- 3 Cumulus MX
- 4 Original cumulus software
A Cumulus Template File is the name given by Steve Loft to any files that contain web tags and need to be processed before they actually include values.
When Cumulus processes any template file, it generates an output file where every included Cumulus web tags has been replaced by values, while any other content is retained unchanged.
Consequently, a single template will actually generate a different file each time Cumulus processes that template because the part of the content that was web tags is now populated with text (values, times, dates, etc.) and, as these values change, a newly generated file is different to the previous generated file.
General Format for Web Tags
In the position, in the template file, where you wish Cumulus to insert the relevant data, place a web tag observing the general format specified here:
<#tag_name [optional input parameters][optional output parameters]>
The tag_name in the general format (see above) is case sensitive, so please type the tag name exactly as shown in the web tag columns in the tables on the [Webtags|web tags page]]. Steve Loft did not define a consistent naming standard, so don't make any assumptions about what case he selected for each character, and remember that some names (as explained later) are less easy to predict than others.
Any input selection parameters always use lower case, so please type them exactly as shown in the sections dealing with input parameters on that page.
Where output formatting parameters are used, they are case insensitive for processing by Delphi parser in legacy Cumulus 1. But for MX, all output parameters are case sensitive, and also dependent on what other output formatters are being used if any, so please read the sections on output parameters and study the examples in the tables carefully.
Template files you add
As explained on this page, template file can generate a variety of file types. People writing their own templates can use any file extension (some popular choices are "tmpl" or "cum" to indicate they are Cumulus templates). To ensure that the template files and generated web pages cannot be confused, Steve Loft realised the "T" notation used by the provided templates may not be part of the name used by third parties for their templates, hence he designed Cumulus such that (for a non-standard name) the generated file will have "tmp" added to the end of the template name you selected, just to remind you of its temporary existence (until the source template is processed again). That "tmp" is removed when the final web page is stored on your web server.
Note by Steve Loft: When you put a tag into your template, be careful that whatever program you are using to develop your web pages doesn't change the angle brackets to slightly different symbols -- this is a common cause of failure!
There are a number of editing tools that are designed for editing programming code and you should use one of those (e.g. Notepad++, Brackets, NoteTab Light, HTML kit, amongst many others), rather than a tool designed for web page design editing (e.g. Dreamweaver, word press, amongst others).
If you want your template file to generate a web page, then this is discussed fully on the Customised templates page, where there is a diagram that explains how file names are affected by your choices in some of the settings for file transfer.
Here I just remind you that Cumulus web tags are the special markers in your template file; during processing of that template file, Cumulus will replace them with the actual values, in the web page it creates. However, this is just one of many ways to build your own website with Hyper-Text Manipulation Language file with your layout, including static text and perhaps graphics, calling a Cascading Style sheet to define the look. Creating a template with all the content needed for a web page means you are uploading large files (with a significant proportion of their content never changing) every time you want new data on your web site, so the next section describes an alternative way to use a template file to get just the data to your web server.
PHP Hypertext Preprocessor (PHP) is another script language, it is parsed on the web server and so the browser only sees what is generated by the PHP script, not the actual script. PHP can do a lot, so it takes some time to learn, but it is very simple in concept, and you should find writing simple scripts is surprisingly easy once you master the syntax. There are many guides to writing PHP online, and you may find the notes on PHP page helpful in a Cumulus context.
- Alternatively, in most script languages, apply ' * 1', i.e. multiply by one, to implicitly convert the tag from string to base 10 number.
- Another alternative is to add zero when a web tag is being assigned to a script variable, this is frequently used in scripts where the web tag being used is not available in all versions of Cumulus, because Cumulus does not implement the concept of null values and often zero is used when a true value is not available because that sensor is not installed for example. Adding 0 means that if the web tag is not recognised, the script is still able to give a variable in its language some value and won't fail because that variable is undefined. If the web tag is available, adding zero does not prevent the true value of that web tag being assigned to the variable.
Inconsistency of web tag names
Some tags are all lower-case, some are camel-case, and some start with a capital letter. Have a look yourself at just how much inconsistency is present in the names in the tables below. The great inconsistency in the naming, gives rise to a problem as it very easy to spell a tag_name incorrectly as you naturally expect there to be a standard pattern.
You will find yourself frequently having to refer to this article, if you decide to make your own Cumulus templates (see section below for more information). This applies whether those templates are for web pages, to implement Extensible Mark-up Language files, or PHP Hypertext Pre-processor scripts.
When Steve Loft introduced the first web tags as part of developing software for his own use, he did not create a naming standard to ensure consistency in the future. As he introduced further web tags at different times, the names used might be consistent amongst the ones introduced that day, but there was still no naming convention to ensure consistency with tags introduced previously or to help name future tags.
Inconsistency for today, yesterday, this month, this year groups
It would be easier if all tags reporting parameters for today were consistent, let alone consistency in naming between tags for today and yesterday. The tags for this year and this month were introduced in same release, so there is some consistency in how they were named then, but no standard to ensure future tags for this month and this year would be named the same way.
Inconsistency in use of "Y"
- The character "Y" might be included in a web tag to denote yesterday, or it might denote this year
- Where the Y is indicating yesterday, it is sometimes a prefix, sometimes a suffix!
Inconsistency in use of "T"
- The newer web tags for today include a "T" as a suffix, the older ones do not.
- The lack of a "T" in some today tags causes some confusion with all-time record tags as they have a similar naming structure to these older today web tags.
- This is particularly confusing and is why you must look up today, and all-time, tags in the tables in this article.
- The time-stamp tags add a "T" to the corresponding web tag for the value, but in an inconsistent way:
- the T is a prefix sometimes and
- the T is a suffix sometimes
- This is particularly confusing and is why you must look up time-stamp tags in the tables in this article.
Choosing script variable names derived from tag names
In the web tag to PHP variable scripts, I have posted, see Php_webtags#Minimised_Upload_size, I have tried to introduce better consistency in the PHP variable names, so "T" is added as a suffix to all "today" variables for example. Some other script authors try to match the inconsistent web tag names, so their script variable names are also inconsistent.
Template files you can customise
These templates use the "T" notation and are found in CumulusMX/web sub-folder.
- realtimegaugesT.txt is included in all releases, it contains the web tags used to produce the latest available values for the "gauges.htm" web page to plot, and is processed at whatever real time interval you have programmed. There are some settings that determine whether it is processed and whether the resulting data file is uploaded.
- websitedataT.json is included in releases from 3.10.1, it is a large file, and probably contains more than you need for your web site. Obviously, as this file is transferred to your web server on every standard update period, it is best to upload only what you need. After all you may choose to use only a sub-set of the default web pages provided with MX. The template file can be edited to exclude any derivatives that you don't want, and/or to add any extras you want.
Early MX releases
These had modified versions of the original Beth Loft web templates in the CumulusMX/web sub-folder. These templates use the "T" notation as with the legacy software, but there is no "originals" sub-folder.
Internal template files
These templates are found in CumulusMX/web sub-folder:
You upload them once if you have the MX default web pages on your web server, as they tell those web pages what settings you have enabled.
The admin interface relies on .json files transferred via the application program interface (api), again these are generated within the code and cannot be modified, although scroll up on the linked Wiki page to find out how you can write customised api calls.
Original cumulus software
Template files provided
There is one template that is held within the legacy Cumulus code, this generates the default Realtime.txt. It is possible to generate different content
The other template files are always installed into a sub-folder: cumulus\web\originals (except for very early versions). As its name suggests, "web" sub-folder holds templates that generate web pages for Cumulus to then upload to your web server.
When you run the install package (see Setup, you can choose whether these web template files are also installed into the parent folder cumulus\web.
- This allows you to use only some of the templates (you only include the ones you want the software to process, and delete the others).
- It also means if you have modified the provided template files (keeping original names), the installation process will not overwrite them and you can continue to have the software process your modified template files.
Steve Loft made it clear that the 'web template files his wife (Beth) designed, were their files, and only included in his software as examples to help you devise your own template files. He said, we never thought that people would use our files without modification. Each of these templates, after processing becomes a fully working web page that can optionally be uploaded to your web server.
To help people using the legacy software, there is more about processing of files on the Customised templates page, but think of a template as containing text that Cumulus copies from the template file to the web page it is constructing. The processing process is basically a parse, each time Cumulus finds a web tag complete with any parameters it needs, Cumulus software looks up the value that it will use to replace that web tag in the web page it is creating before moving on through the text.
The example web templates provided by Cumulus insert a "T" at the end of the intended web page name before the extension (.htm or .html), so that the template files and generated web pages cannot be confused.
You may find the information on the FAQ page helps answer some of your questions.
Your own templates
- As the Setup page, and the notes above, indicate, the legacy cumulus software uses a subfolder "originals" to keep the example web templates safe, allowing you to do edits in the cumulus\web folder above that.
- Such edits, as already mentioned, allow you to modify provided templates.
- Alternatively, you can write your own templates, with any names you like, place them in a new folder you create (perhaps called "cumulus Templates") and using the advice in Customised templates use them.
To summarise the necessary tasks:
- You can create a template file that has a structure of HTML elements with Cumulus web tags to represent the information you want included.
- Next you ask Cumulus to process that template file, it will create a HTML page from the template, and during that file creation replace the tag with the current value of the item the tag represents.
- You also need to tell Cumulus that the resulting HTML file is to be uploaded to the internet (or copied to a local web server).