Cumulus template file: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
3,961 bytes added ,  22:10, 8 April 2021
m
 
(11 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Introduction=
=Introduction=


 
[[Category:WebTips]]
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.  
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 these files it generates output files where the tags/tokens have been replaced by values.  
When Cumulus processes any template file, it generates an output file where every included [[Webtags|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.
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.


=Original cumulus software=
==General Format for Web Tags==


==Template files provided==
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:  <pre><#tag_name [optional input parameters][optional output parameters]></pre>


==== Case sensitivity ====


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 '''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 [[#Inconsistency_of_web_tag_names|explained later]]) are less easy to predict than others.
 
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 modifed 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.
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.


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.
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.
 
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#Website|FAQ]] page helps answer some of your questions.
=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.


==Template files you add==


The page dealing with the customisation of web templates is [[Customised templates]], and it includes a diagram that explains how file names are affected by your choices in some of the settings for file transfer.
''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!'' 


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 you choose, hence the generated file will have "tmp" added to the end of the template name you selected, just to remind you of its temporary existance until the source template is processed again.  That "tmp" is removed when the final web page is stored on your web server.
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).


=== Using web tags in templates for creating HTML pages ===
=== Using web tags in templates for creating HTML pages ===


You can include special markers in your template file that are called web tags; during processing Cumulus will replace them with the actual values.
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.


Typically you would use this to build your own website by having an HTML template file with your layout, static text and graphics.  In the position on the page you wish Cumulus to insert the relevant data place a web tag in the general format specified here:  <pre><#tag_name [optional input parameters][optional output parameters]></pre>
Here I just remind you that [[Webtags|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 lookCreating 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.


''Note: 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).
=== Using web tags in scripts ===
 
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 [[Customised_templates#What_to_select_on_the_.27Files.27_tab_of_the_Internet_Settings_screen_within_the_.27Configuration.27_menu|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).
 
 
==== Case sensitivity ====


The tag_name in the general format 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]].
As mentioned in previous section, it is inefficient to create a template file where the majority of the content is not web tags and so never changes. JavaScript Object Notation (JSON) files are probably the most efficient way for template files to include just web tags, with minimal structure around them. (In fact MX uses this approach).


The optional input parameters always use lower case, so please type them exactly as shown in the sections dealing with input parameters on that page.
If your JavaScript is less structured, then a .js script template can perform arithmetic, and/or validation, on web tags. This gives you more flexibility about how information appears on your web page, and it can support graphical ways of presenting data. JavaScript files can be called from a web page when it is viewed in a browser; consequently, your HTML file can be a static file on your web server, and call a JavaScript file that Cumulus has generated and uploaded, and that script can amend the contents of table cells in your HTML to display the latest data. A variant is AJAX, where a timer allows a fresh JavaScript file to be uploaded (without reloading the web page) and thus refresh the table cell contents; this is discussed elsewhere on more technical pages of this wiki (see [[:Category:WebTips]]).
*As JavaScript can not understand a real number that has the integer and decimal parts separated by a comma, but your computer may be set to use that representation in standard tags, there are special versions of many tags to use in script - see [[Webtags#No_Commas|tags with commas removed]] section.
*JavaScript is available in every modern browser (Microsoft's Internet Explorer initially used a different language '''jScript'''), but actually it is hard to get right. A human being recognises something as a number or text or operation. Programmers writing in JavaScript can use Objects, but you need to be skilled to do that. Without Objects, it is easy to write code that gets text and numbers confused; for example you can have two variables ('''door1''' and '''door2''') defining width of two adjacent doors and want total opening size in variable '''Opening'''. The code <tt>Opening  = door1 + door2;</tt> generally will just concatenate the text, rather than add them as numbers!  There is some guidance below on how to use "parse" functions to make JavaScript recognise numbers.


The optional output parameters are case insensitive when used in Cumulus 1. But for Cumulus 2 and later, so this includes MX, the 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.
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.


=== Using web tags in scripts ===
*You can also use the tags within script, this might be a PHP script, or JavaScript either embedded in HTML, or in external files, to transfer the values (or the result of calculations based on those values) to your web server for further processing.
*As JavaScript can not understand a real number that has the integer and decimal parts separated by a comma, but your computer may be set to use that representation in standard tags, there are special versions of many tags to use in script - see [[#No_Commas|tags with commas removed]] section.
*Note that if a PHP or JavaScript file contains any Cumulus web tags then you must [[Customised_templates#What_to_select_on_the_.27Files.27_tab_of_the_Internet_Settings_screen_within_the_.27Configuration.27_menu|ask Cumulus to process]] the script file.
*Note that if a PHP or JavaScript file contains any Cumulus web tags then you must [[Customised_templates#What_to_select_on_the_.27Files.27_tab_of_the_Internet_Settings_screen_within_the_.27Configuration.27_menu|ask Cumulus to process]] the script file.
*JavaScript processing code can be embedded in a template that is already being processed into HTML. (This technique has been used  in the standard 'monthlyrecordT.htm' template).
*JavaScript processing code can be embedded in a template that is already being processed into HTML. (This technique has been used  in the standard 'monthlyrecordT.htm' template).
*Alternatively embed a bit of JavaScript assignment code in HTML, that is already been processed, to convert the tags to a collection of string variables and use those variable names in any external script called from the HTML file. (This technique has been used in the standard 'gaugesT.htm' template).
*Alternatively embed a bit of JavaScript assignment code in HTML, that is already been processed, to convert the tags to a collection of string variables and use those variable names in any external script called from the HTML file. (This technique has been used in the standard 'gaugesT.htm' template in the legacy Cumulus 1 software).
*To use the value from a tag as an integer in JavaScript assigning code you need to use a  
*To use the value from a tag as an integer in JavaScript assigning code you need to use a  
<pre>integer_variable_name=parseInt(string_variable_name,10)</pre> type conversion
<pre>integer_variable_name=parseInt(string_variable_name,10)</pre> type conversion
Line 74: Line 57:
*Alternatively, in most script languages, apply ' * 1', i.e. multiply by one, to implicitly convert the tag from string to base 10 number.
*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.
*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==
==Inconsistency of web tag names==
Line 137: Line 119:


The admin interface relies on .json files transferred via the [[Cumulus_MX_Local_API#Predetermined_Data|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.
The admin interface relies on .json files transferred via the [[Cumulus_MX_Local_API#Predetermined_Data|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#Website|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 [[Customised_templates#What_to_select_on_the_.27Files.27_tab_of_the_Internet_Settings_screen_within_the_.27Configuration.27_menu|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).
[[Category:Cumulus MX]]
5,838

edits

Navigation menu