public method

Returns a charset meta-tag for declaring the encoding of the document.

The terms character set (here: charset) and character encoding (here: encoding) were historically synonymous. The terms now have related but distinct meanings. Whenever possible Lithium tries to use precise terminology. Since HTML uses the term charset we expose this method under the exact same name. This caters to the expectation towards a HTML helper. However the rest of the framework will use the term encoding when talking about character encoding.

It is suggested that uppercase letters should be used when specifying the encoding. HTML specs don't require it to be uppercase and sites in the wild most often use the lowercase variant. On the other hand must XML parsers (those may not be relevant in this context anyway) not support lowercase encodings. This and the fact that IANA lists only encodings with uppercase characters led to the above suggestion.


  • string $encoding

    The character encoding to be used in the meta tag. Defaults to the encoding of the Response object attached to the current context. The default encoding of that object is UTF-8. The string given here is not manipulated in any way, so that values are rendered literally. Also see above note about casing.



A meta tag containing the specified encoding (literally).


	public function charset($encoding = null) {
		if ($response = $this->_context->response()) {
			$encoding = $encoding ?: $response->encoding;
		return $this->_render(__METHOD__, 'charset', compact('encoding'));