00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Core_Block_Template extends Mage_Core_Block_Abstract
00036 {
00037
00038
00039
00040
00041
00042
00043 protected $_viewDir = '';
00044
00045
00046
00047
00048
00049
00050 protected $_viewVars = array();
00051
00052 protected $_baseUrl;
00053
00054 protected $_jsUrl;
00055
00056 protected static $_showTemplateHints;
00057 protected static $_showTemplateHintsBlocks;
00058
00059 public function getTemplate()
00060 {
00061 return $this->_getData('template');
00062 }
00063
00064 public function getArea()
00065 {
00066 return $this->_getData('area');
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076 public function assign($key, $value=null)
00077 {
00078 if (is_array($key)) {
00079 foreach ($key as $k=>$v) {
00080 $this->assign($k, $v);
00081 }
00082 }
00083 else {
00084 $this->_viewVars[$key] = $value;
00085 }
00086 return $this;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 public function setScriptPath($dir)
00096 {
00097 $this->_viewDir = $dir;
00098 return $this;
00099 }
00100
00101 public function getDirectOutput()
00102 {
00103 if ($this->getLayout()) {
00104 return $this->getLayout()->getDirectOutput();
00105 }
00106 return false;
00107 }
00108
00109 public function getShowTemplateHints()
00110 {
00111 if (is_null(self::$_showTemplateHints)) {
00112 self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
00113 && Mage::helper('core')->isDevAllowed();
00114 self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
00115 && Mage::helper('core')->isDevAllowed();
00116 }
00117 return self::$_showTemplateHints;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 public function fetchView($fileName)
00127 {
00128 Varien_Profiler::start($fileName);
00129
00130 extract ($this->_viewVars);
00131 $do = $this->getDirectOutput();
00132
00133 if (!$do) {
00134 ob_start();
00135 }
00136 if ($this->getShowTemplateHints()) {
00137 echo '<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;"><div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="'.$fileName.'">'.$fileName.'</div>';
00138 if (self::$_showTemplateHintsBlocks) {
00139 $thisClass = get_class($this);
00140 echo '<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="'.$thisClass.'">'.$thisClass.'</div>';
00141 }
00142 }
00143
00144 include $this->_viewDir.DS.$fileName;
00145
00146 if ($this->getShowTemplateHints()) {
00147 echo '</div>';
00148 }
00149
00150 if (!$do) {
00151 $html = ob_get_clean();
00152 } else {
00153 $html = '';
00154 }
00155 Varien_Profiler::stop($fileName);
00156 return $html;
00157 }
00158
00159
00160
00161
00162
00163
00164 public function renderView()
00165 {
00166 Varien_Profiler::start(__METHOD__);
00167
00168 $this->setScriptPath(Mage::getBaseDir('design'));
00169 $params = array('_relative'=>true);
00170 if ($area = $this->getArea()) {
00171 $params['_area'] = $area;
00172 }
00173
00174 $templateName = Mage::getDesign()->getTemplateFilename($this->getTemplate(), $params);
00175
00176 $html = $this->fetchView($templateName);
00177
00178 Varien_Profiler::stop(__METHOD__);
00179
00180 return $html;
00181 }
00182
00183
00184
00185
00186
00187
00188 protected function _toHtml()
00189 {
00190 if (!$this->getTemplate()) {
00191 return '';
00192 }
00193 $html = $this->renderView();
00194 return $html;
00195 }
00196
00197
00198
00199
00200
00201
00202 public function getBaseUrl()
00203 {
00204 if (!$this->_baseUrl) {
00205 $this->_baseUrl = Mage::getBaseUrl();
00206 }
00207 return $this->_baseUrl;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 public function getJsUrl($fileName='')
00219 {
00220 if (!$this->_jsUrl) {
00221 $this->_jsUrl = Mage::getBaseUrl('js');
00222 }
00223 return $this->_jsUrl.$fileName;
00224 }
00225
00226 }