From f19615a3be54dbf994908d758974a040887bd25d Mon Sep 17 00:00:00 2001 From: Gilles Wittenberg Date: Sat, 18 May 2013 20:25:19 +0200 Subject: [PATCH] Allow setting different type on scriptBlock --- lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php | 10 ++++++++++ lib/Cake/View/Helper/HtmlHelper.php | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index 343486f97..fef74c7f1 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -1067,6 +1067,16 @@ class HtmlHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Html->scriptBlock('window.foo = 2;', array('type' => 'text/x-handlebars-template')); + $expected = array( + 'script' => array('type' => 'text/x-handlebars-template'), + $this->cDataStart, + 'window.foo = 2;', + $this->cDataEnd, + '/script', + ); + $this->assertTags($result, $expected); + $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index e45e732a3..c650aa739 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -98,7 +98,7 @@ class HtmlHelper extends AppHelper { 'ol' => '%s', 'li' => '%s', 'error' => '%s', - 'javascriptblock' => '', + 'javascriptblock' => '%s', 'javascriptstart' => '', 'javascriptend' => '' @@ -560,7 +560,7 @@ class HtmlHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock */ public function scriptBlock($script, $options = array()) { - $options += array('safe' => true, 'inline' => true); + $options += array('type' => 'text/javascript', 'safe' => true, 'inline' => true); if ($options['safe']) { $script = "\n" . '//' . "\n"; }