Customised templates: Difference between revisions

m (→‎What is meant by 'Cumulus processes templates': Possibility of processing CSS)
 
If a particular webpage on a local web server includes a script requiring loading a local file like 'dayfile.txt', then just for that webpage enter its remote web file name, and select Binary and File Transfer Process, as per the previous set of instructions. (The remaining pages will be copied across locally using the specified full path without FTP as per instructions directly above).
 
 
= Using PHP Hypertext Pre-processor =
This Wiki article cannot teach you PHP, but it can give you some pointers.
 
== Using PHP templates ==
This approach incorporates some PHP script in a page that still contains Cumulus web tags so still requires processing by Cumulus. This is suitable when you want to try PHP, but do not want a big redesign of your set-up.
*The file still contains the HTML shown earlier, indeed it might be a simple edit of a standard cumulus template.
*It still contains Cumulus web tags, but as it is no longer a standard page, it has to be listed on the ''Files'' tab of the '''Internet''' screen within the 'Configuration' menu; the remote file name must have the extension ".php" so that the PHP processor will parse the file, before it is passed to the browser as a HTML page.
*The php script might be used for a decision more complicated than the [[Webtags_as_boolean_operators_in_HTML|boolean options]] that can be achieved just with standard HTML. For example, in the UK vehicle headlights must be used between half-an hour after sunset to half-an-hour before sunrise, so maybe you want to modify your "todayT.htm" page that becomes "today.htm" so it becomes "today.php" instead and incorporates 2 new chunks of code:
<code>
&lt;?php // start of PHP script setting new variables not available in Cumulus web tags
 
// end of lighting up time (hours of darkness)
 
$darkness_end = new DateTime($latestDay.' '.$sunrise); // sunrise
 
$darkness_end -> sub(DateInterval::createFromDateString('30 minutes')); // subtract 30 minutes
 
// start of lighting up time (hours of darkness)
 
$darkness_start= new DateTime($latestDay.' '.$sunset); // sunset
 
$darkness_start-> add(new DateInterval('P0Y0DT0H30M')); // add 30 minutes
 
?> <!-- end of PHP script -->
 
....
&lt;tr>
&lt;th title="Darkness times calculated by PHP">Darkness starts</th>
&lt;td>&lt;?php
echo ($darkness_start->format('g:i a'));
?></td>
</tr>&lt;tr>
&lt;th>Darkness ends</th>
&lt;td>&lt;?php
echo ($darkness_end->format('g:i a'));
?></td>
</tr>
</code>
 
== Replacing HTML by PHP ==
#A more efficient approach, this is a bigger implementation change, is to set Cumulus to process just [[Php_webtags| this file]] to create PHP variables/arrays from the Cumulus web tags you want to use.
#Then you create a new PHP script that does not get processed by Cumulus. For example "thismonth.php" would start with the same HTML5 as shown above, but the table is output by the PHP script:
<code><!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="<#location> weather data" />
<meta name="keywords" content="Cumulus, <#location> weather data, weather, data, weather station" />
<title>&lt;?php
include 'cumuluswebtags.php';
echo "$location";
?>weather</title>
<link href="weatherstyle.css" rel="stylesheet" type="text/css" />
</head>
 
&lt;body>
&lt;div id="content">
&lt;h1>&lt;?php
echo "$location";
?> weather</h1>
....
&lt;table style="width:100%;border-collapse: collapse; border-spacing: 0;" >
&lt;caption>This month's highs and lows</caption>
&lt;tr>
&lt;td colspan="3" class="tableseparator_temp">Temperature and Humidity </td>
</tr>
&lt;tr class="td_temperature_data">
&lt;?php
echo "&lt;th>Highest</th>";
echo "&lt;td>$MonthTempH $tempunit</td>";
echo "&lt;td>$MonthTempHT on $MonthTempHD</td>";
echo "&lt;th>Lowest</th>";
echo "&lt;td>$MonthTempL $tempunit</td>";
echo "&lt;td>$MonthTempLT on $MonthTempLD</td>";
?>
&lt;/tr>
 
....
 
echo &lt;&lt;&lt; END_OF_QUOTE
&lt;tr>
&lt;td colspan="2" class="spacer">Pressure (sea level)</td>
</tr>
&lt;tr>
&lt;th class="labels">Lowest</th>
&lt;td class="site_data">$MonthPressL {$pressunit}</td>
&lt;td class="time_stamp">at $MonthPressLT on $MonthPressLD</td>
</tr>
&lt;tr>
&lt;th class="labels">Highest</th>
&lt;td class="site_data">$MonthPressH {$pressunit}</td>
&lt;td class="time_stamp">at $MonthPressHT on $MonthPressHD</td>
</tr>
</table>
END_OF_QUOTE;
 
....
 
</code>
Note that only excerpts from the code are shown. Note the two ways of getting PHP to output HTML code, either by using separate echo commands for each line or using the "heredoc" approach so that one echo can be applied to multiple lines. In the latter way, the syntax allows a space after echo and after <<< but does not allow any other spaces (or tabs) in the enclosing lines.
5,838

edits