Php webtags: Difference between revisions

2 bytes removed ,  09:02, 20 April 2020
m
Line 201: Line 201:
Use the PHP [http://www.w3schools.com/PHP/php_includes.asp include/require] command to include the Cumulus web tags into your PHP file.  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.  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.
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.


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:
Line 244: Line 244:
<?php } ?>
<?php } ?>
</pre>
</pre>
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.


==Example==
==Example==
5,838

edits