Cumulus template file: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
m
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> mightgenerally returnwill thejust correctconcatenate numberthe if it recognises these are numbers (because they contain a decimal point)text, orrather itthan might treatadd them as textnumbers! (especially if theyThere areis integers)some andguidance justbelow concatenateon thehow text!to See bullet point below whereuse "parseIntparse" is usedfunctions to make JavaScript recognise integers as numbers.
 
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==
5,838

edits

Navigation menu