Parameter encoding

There is one small problem in the previous example: if the author's name contains a < character, the generated output might look something like this:

<a href=""> Joe<Blow </a>

and the < character will cause problems in an HTML browser.

Awasu automatically handles this by checking the extension of the output file and encoding values appropriately e.g. in the example above, if the output file had a .HTM or .HTML (or .XML) extension, the problematic < character would be inserted as &amp;.


However, there may be cases where the default handling is not enough and so you can force encoding by adding encode and chars arguments to the template parameter. For example:

{%CHANNEL-METADATA% author encode=sgml chars=<&"}

This insert the channel's author but SGML-encodes the three special characters specified.

The encode argument may have the values json, jsonval, sgml, attr, percent, csv, or none .


The previous example also suffers from the same problem when generating the mailto: link, if the email address contains a " character.

The code below shows how both these issues can be fixed:

    {%?CHANNEL-METADATA% author/email}
        <a href="mailto:{%@% encode=sgml chars=<&\"}">
        {%CHANNEL-METADATA% author encode=sgml chars=<&\"}
    {%?CHANNEL-METADATA% author/email}
    No author was specified!
This example code works fine if a channel has only one author specified but if there's more than one, it will only show the first one. How to handle multiple authors is described here.