Adding $scripts_for_layout view variable, View::addScript(), and extra parameters to relevant HtmlHelper methods

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3438 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-08-28 20:41:08 +00:00
parent 05d954a5bf
commit 88079265b2
2 changed files with 44 additions and 4 deletions

View file

@ -148,7 +148,7 @@ class HtmlHelper extends Helper {
* @param array $attributes
* @return string
*/
function meta($title = null, $url = null, $attributes = array()) {
function meta($title = null, $url = null, $attributes = array(), $inline = true) {
$types = array('html' => 'text/html', 'rss' => 'application/rss+xml', 'atom' => 'application/atom+xml');
if (!isset($attributes['type']) && is_array($url) && isset($url['ext'])) {
@ -168,7 +168,13 @@ class HtmlHelper extends Helper {
if (!isset($attributes['rel'])) {
$attributes['rel'] = 'alternate';
}
return $this->output(sprintf($this->tags['metalink'], $this->url($url, true), $title, $this->_parseAttributes($attributes)));
$out = $this->output(sprintf($this->tags['metalink'], $this->url($url, true), $title, $this->_parseAttributes($attributes)));
if ($inline) {
return $out;
} else {
$this->view->addScript($out);
}
}
/**
* Returns a charset META-tag.
@ -308,16 +314,23 @@ class HtmlHelper extends Helper {
* @param string $path Path to CSS file
* @param string $rel Rel attribute. Defaults to "stylesheet".
* @param array $htmlAttributes Array of HTML attributes.
* @param boolean $inline
* @return string CSS <link /> or <style /> tag, depending on the type of link.
*/
function css($path, $rel = 'stylesheet', $htmlAttributes = array()) {
function css($path, $rel = 'stylesheet', $htmlAttributes = array(), $inline = true) {
$url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . $this->themeWeb . CSS_URL . $path . ".css";
if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');');
} else {
$out = sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' '));
}
return $this->output($out);
$out = $this->output($out);
if ($inline) {
return $out;
} else {
$this->view->addScript($out);
}
}
/**
* Creates a submit widget.

View file

@ -110,6 +110,14 @@ class View extends Object{
*/
var $_viewVars = array();
/**
* Scripts (and/or other <head /> tags) for the layout
*
* @var array
* @access private
*/
var $__scripts = array();
/**
* Title HTML element of this View.
*
@ -418,6 +426,7 @@ class View extends Object{
array(
'title_for_layout' => $pageTitle,
'content_for_layout' => $content_for_layout,
'scripts_for_layout' => join("\n\t", $this->__scripts),
'cakeDebug' => $debug
)
);
@ -475,6 +484,24 @@ class View extends Object{
return $this->_viewVars[$var];
}
}
/**
* Adds a script block or other element to be inserted in $scripts_for_layout in
* the <head /> of a document layout
*
* @param string $name
* @param string $content
* @return void
* @access public
*/
function addScript($name, $content = null) {
if ($content == null) {
if (!in_array($content, array_values($this->__scripts))) {
$this->__scripts[] = $name;
}
} else {
$this->__scripts[$name] = $content;
}
}
/**
* @deprecated
*/