Permalink
Browse files

Updates HTML helper to correctly return charset tag if using doctype …

…HTML5

Ex.:
First use
$this->Html->docType('html5');
Then:
$this->Html->charset();

HTH
  • Loading branch information...
lipedjow committed Apr 2, 2011
1 parent f4d8a7e commit af4c45a333b123ade8ea38577b42658c9566121c
Showing with 24 additions and 3 deletions.
  1. +24 −3 cake/libs/view/helpers/html.php
@@ -78,7 +78,10 @@ class HtmlHelper extends AppHelper {
'legend' => '<legend>%s</legend>',
'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
'style' => '<style type="text/css"%s>%s</style>',
- 'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
+ 'charset' => array(
+ 'default' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
+ 'html5' => '<meta charset="%s" />',
+ ),
'ul' => '<ul%s>%s</ul>',
'ol' => '<ol%s>%s</ol>',
'li' => '<li%s>%s</li>',
@@ -135,6 +138,15 @@ class HtmlHelper extends AppHelper {
* @access protected
*/
protected $_scriptBlockOptions = array();
+
+/**
+ * Document type setted
+ *
+ * @var string
+ * @access private
+ */
+ private $_docType = null;
+
/**
* Document type definitions
*
@@ -199,6 +211,7 @@ public function addCrumb($name, $link = null, $options = null) {
*/
public function docType($type = 'xhtml-strict') {
if (isset($this->__docTypes[$type])) {
+ $this->_docType = $type;
return $this->__docTypes[$type];
}
return null;
@@ -284,11 +297,19 @@ public function meta($type, $url = null, $options = array()) {
* @access public
* @link http://book.cakephp.org/view/1436/charset
*/
- public function charset($charset = null) {
+ public function charset($charset = null, $doctype = null) {
if (empty($charset)) {
$charset = strtolower(Configure::read('App.encoding'));
}
- return sprintf($this->_tags['charset'], (!empty($charset) ? $charset : 'utf-8'));
+
+ if(empty($doctype) || !isset($this->_tags['charset'][$doctype])) {
+ if(!empty($this->_docType) && isset($this->_tags['charset'][$this->_docType])) {
+ $doctype = $this->_docType;
+ } else {
+ $doctype = 'default';
+ }
+ }
+ return sprintf($this->_tags['charset'][$doctype], (!empty($charset) ? $charset : 'utf-8'));
}
/**

0 comments on commit af4c45a

Please sign in to comment.