Php webtags: Difference between revisions

3 bytes added ,  18:28, 26 June 2020
m
Line 245: Line 245:
Use the PHP [http://www.w3schools.com/PHP/php_includes.asp include/require] command to include the Cumulus web tags into your PHP file. (If you choose a template that includes function definitions as some of them do to permit you to list the source; then you must use '''include_once 'filename';''' or ''require_once 'filename';'').  Then where you would insert a web tag if you were writing a template, you insert a command to "echo" the php variable <pre><?=$PHP_variable_name[any_index_needed];?></pre>
Use the PHP [http://www.w3schools.com/PHP/php_includes.asp include/require] command to include the Cumulus web tags into your PHP file. (If you choose a template that includes function definitions as some of them do to permit you to list the source; then you must use '''include_once 'filename';''' or ''require_once 'filename';'').  Then where you would insert a web tag if you were writing a template, you insert a command to "echo" the php variable <pre><?=$PHP_variable_name[any_index_needed];?></pre>


The "=" in the above example is shorthand for " echo " with the spacing shown. In most of the ready made files listed for download on this page the PHP variable names are either identical to their [[webtags]] equivalent or have a name that reflects the output parameters selected, but of course if you are editing the file you might choose different names. For example in provided code, the Cumulus webtag <tt><#forecast></tt> would be referred to as <tt>$forecast</tt> in your PHP file.
The "=" in the above example is shorthand for " echo " with the spacing shown. In some of the ready made files listed for download on this page the PHP variable names are either identical to their [[webtags]] equivalent or have a name that reflects the output parameters selected, but of course if you are editing the file you might choose different names. For example you might find that the Cumulus web tag <tt><#forecast></tt> would be referred to as <tt>$forecast</tt> in your PHP file.


However the beauty of using script (PHP or another) is that you can add other aspects of the script language like conditions and control what HTML is output. For instance if a PHP variable tells you it is not raining you might leave out displaying the current rain rate. Or if it is night time you might report fewer derivatives than if it is day time. If it is the first day of a month, then you can leave out the rows in your table that would report the highest and lowest for the month that are not yet defined. Such php script might look something like this example that wants alternating rows to look different and has to adapt that if one row is left out:
However the beauty of using script (PHP or another) is that you can add other aspects of the script language like conditions and control what HTML is output. For instance if a PHP variable tells you it is not raining you might leave out displaying the current rain rate. Or if it is night time you might report fewer derivatives than if it is day time. If it is the first day of a month, then you can leave out the rows in your table that would report the highest and lowest for the month that are not yet defined. Such php script might look something like this example that wants alternating rows to look different and has to adapt that if one row is left out:
5,838

edits