Changes

Jump to navigation Jump to search
m
Added Template:Note box
Line 93: Line 93:     
If you look at the new /etc/crontab file, you will see that the template processor has replaced the block between the braces with the actual email address of the administrator, which is defined in the accounts database.
 
If you look at the new /etc/crontab file, you will see that the template processor has replaced the block between the braces with the actual email address of the administrator, which is defined in the accounts database.
 +
{{Note box|msg=Be careful with the placement of the braces in the example. We want two lines of output - the comment and the line starting with the asterisk. If you move the opening brace onto a new line, you will end up with three lines of output.
   −
<div class="NOTE"><blockquote class="NOTE">
+
Whitespace is not signifcant and the code within braces should be formatted "nicely". However, ''whitespace outside braces is significant'' and will be copied literally to the output file.}}
 
  −
'''Note: '''Be careful with the placement of the braces in the example. We want two lines of output - the comment and the line starting with the asterisk. If you move the opening brace onto a new line, you will end up with three lines of output.
  −
 
  −
Whitespace is not signifcant and the code within braces should be formatted "nicely". However, <span class="emphasis">''whitespace outside braces is significant''</span> and will be copied literally to the output file.
  −
 
  −
</blockquote></div>
      
You could check that value with the '''db accounts show admin''' command. With this change to the template, the message which will go to the <tt class="FILENAME">/var/log/messages</tt> log file every 20 minutes will contain the actual current administrative email address, rather than a hardcoded text message.
 
You could check that value with the '''db accounts show admin''' command. With this change to the template, the message which will go to the <tt class="FILENAME">/var/log/messages</tt> log file every 20 minutes will contain the actual current administrative email address, rather than a hardcoded text message.
Line 316: Line 311:  
     Interval=20
 
     Interval=20
 
     status=enabled
 
     status=enabled
 
+
{{Note box|By convention, database keys are lower case, and property names are mixed case (e.g. Interval). The status property is an exception here, and is stored lower case.}}
<div class="NOTE"><blockquote class="NOTE">
  −
 
  −
'''Note: '''By convention, database keys are lower case, and property names are mixed case (e.g. Interval). The status property is an exception here, and is stored lower case.
  −
 
  −
</blockquote></div>
      
Now edit the <tt class="FILENAME">25templatedemo</tt> file to look like this:
 
Now edit the <tt class="FILENAME">25templatedemo</tt> file to look like this:
Line 344: Line 334:  
  }
 
  }
 
</nowiki>
 
</nowiki>
 
+
{{Note box|msg=The variable <var class="LITERAL">$OUT</var> is a special variable used for output from a template. It is documented in the <code class="CLASSNAME">Text::Template</code> documentation. For now, just think about it as the return value from the template, so set it to the value you want to print from this fragment. Note also that a template fragment can return static text without setting <var class="LITERAL">$OUT</var> directly, as shown on the <var class="LITERAL">return</var> line above.}}
<div class="NOTE"><blockquote class="NOTE">
  −
 
  −
'''Note: '''The variable <var class="LITERAL">$OUT</var> is a special variable used for output from a template. It is documented in the <code class="CLASSNAME">Text::Template</code> documentation. For now, just think about it as the return value from the template, so set it to the value you want to print from this fragment. Note also that a template fragment can return static text without setting <var class="LITERAL">$OUT</var> directly, as shown on the <var class="LITERAL">return</var> line above.
  −
 
  −
</blockquote></div>
      
This is more complicated than the original template, but it is also more flexible. Note that the initial comment (<var class="LITERAL"><nowiki># Template demo crontab entry</nowiki></var>) is hardcoded, but the line that follows is generated from the configuration database parameters. The code in the template retrieves the <span class="emphasis">''loggerdemo''</span> service entry, retrieves the required properties, and returns the appropriate output. To experiment, try different combinations of parameters:
 
This is more complicated than the original template, but it is also more flexible. Note that the initial comment (<var class="LITERAL"><nowiki># Template demo crontab entry</nowiki></var>) is hardcoded, but the line that follows is generated from the configuration database parameters. The code in the template retrieves the <span class="emphasis">''loggerdemo''</span> service entry, retrieves the required properties, and returns the appropriate output. To experiment, try different combinations of parameters:
Line 467: Line 452:  
  1;
 
  1;
 
</nowiki>
 
</nowiki>
 
+
{{Note box|msg=This code example calls expand-template. This is used for illustrative purposes only. All templates should be expanded by signalling events.}}
<div class="NOTE"><blockquote class="NOTE">
  −
 
  −
'''Note: '''This code example calls expand-template. This is used for illustrative purposes only. All templates should be expanded by signalling events.
  −
 
  −
</blockquote></div>
      
Similarly to events and actions, the <tt class="FILENAME">/etc/e-smith/web/functions/</tt> directory is a repository of potentially available functions. To make the new function actually show up in the user interface, create a symbolic link to it from the web manager cgi-bin directory, as follows:
 
Similarly to events and actions, the <tt class="FILENAME">/etc/e-smith/web/functions/</tt> directory is a repository of potentially available functions. To make the new function actually show up in the user interface, create a symbolic link to it from the web manager cgi-bin directory, as follows:
Line 542: Line 522:     
Now, re-select the <span class="emphasis">''Logger''</span> function and the tags should now be replaced by English phrases. We can very easily add translations for other languages by adding new locale files in the same hierarchy.
 
Now, re-select the <span class="emphasis">''Logger''</span> function and the tags should now be replaced by English phrases. We can very easily add translations for other languages by adding new locale files in the same hierarchy.
 
+
{{Note box|msg=The <var class="LITERAL">LABEL_LOGGERDEMO_INTERVAL</var> tags has intentionally been left untranslated. Why don't you fix it now?}}
<div class="NOTE"><blockquote class="NOTE">
+
</div></div><div class="SECT1">
 
  −
'''Note: '''The <var class="LITERAL">LABEL_LOGGERDEMO_INTERVAL</var> tags has intentionally been left untranslated. Why don't you fix it now?
  −
 
  −
</blockquote></div></div></div><div class="SECT1">
   
----
 
----
   Line 571: Line 547:     
Now the example should work just as before. You can edit the loggerdemo settings in the web manager, and see that the /etc/crontab file changes. But now other applications can also receive notifications of the loggerdemo-update event, by creating symbolic links from the <tt class="FILENAME">/etc/e-smith/events/loggerdemo-update</tt> directory.
 
Now the example should work just as before. You can edit the loggerdemo settings in the web manager, and see that the /etc/crontab file changes. But now other applications can also receive notifications of the loggerdemo-update event, by creating symbolic links from the <tt class="FILENAME">/etc/e-smith/events/loggerdemo-update</tt> directory.
 
+
{{Note box|msg=Panel implementation code should <span class="emphasis">''always''</span> signal events, and should <span class="emphasis">''never''</span> expand templates or modify files directly. These modifications should only be peformed in events.}}
<div class="NOTE"><blockquote class="NOTE">
+
</div><div class="SECT1">
 
  −
'''Note: '''Panel implementation code should <span class="emphasis">''always''</span> signal events, and should <span class="emphasis">''never''</span> expand templates or modify files directly. These modifications should only be peformed in events.
  −
 
  −
</blockquote></div></div><div class="SECT1">
   
----
 
----
  

Navigation menu