Domanda

To make my website look-and-feel consistent, I heavily use SSI. All my pages have the same header (save for the title) and footer. These act like templates and are included with an SSI directive. Variable field content is provided throug SSI #set-variables.

This is the nearest equivalent to "functions" I found without resorting to HTML generators.

A standard page structure is as follows:

<!--#set var="PageTitle" value="Référence" -->
<!--#include virtual="/header.shtml" -->
<section>
    Specific page content
</section>
<!--#include virtual="/footer.shtml" -->

File header.shtml contains <!DOCTYPE > <html> <head> ... </head> <<body> <header> ... </header> and similarly <footer> ... </footer> </body> </html> for footer.shtml.

File header.shtml creates the title for the page with an element:

<title><!--#echo var="PageTitle" --></title>

Everything is fine as long as my title string for variable PageTitle contains only printable ASCII character (i.e. as long as I'm writing in English). Things become more complicated if I want to insert a title in any language using characters outside the ASCII printable set.

If this string is put asis in the <title> element, there is no problem.

As an exemple, the French word above print as Référence. The UTF-8 sequence \x52 \x53 \xA9 ... prints as if it were ISO-8859-x. \x53 \xA9 is the UTF-8 sequence for \xC0 + \x29 = U+00E9 LATIN SMALL LETTER E WITH ACUTE, which is the desired character.

I have tried to use some encoding= attribute in the #echo directive, to no avail, since it affects ISO-8859-1 special characters and does not seem to understand UTF-8.

From what I see in the HTML sent by the server, the string uses entity references for any "dubious" character:

R&#195;&#169;f&#195;&#169;rence

Is there a way to put Apache SSI #echo processing in "transparent" mode?

Apache manual says encoding= defaults to entity (which I get as a result). It can also be set to URL to protect URLs against malicious use (i.e. % escape). But, there is no none setting.

Of course, as a workaround, I could use directly character entity references in the string, but this is not user-friendly: it is much more comfortable to type a character which is accessible from the keyboard and having the target character on screen eases proof-reading.

Edit:

SOLVED!

Solved, but I don't know if it is "standard".

I tried adding encoding="none" in the offending #echo statement and everything went fine!

Now, I must check if this is available across different Apache versions.

È stato utile?

Soluzione

I'm adding this answer since the one above did not exactly solve it for me:

Make sure that the echo statement uses encoding="none" -- and be sure to set it before the var rather than after.

For some reason this works:

<!--#echo encoding="none" var="pageTitle" -->

but this does not:

<!--#echo var="pageTitle" encoding="none" -->

Altri suggerimenti

<--#echo var="PageTitle" --> is missing the vertical bar/pipe.

I haven't read the whole page, so not sure if this is the actual cause of your problem, but it needs to be rectified if you are using that.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top