Hledání layoutu v nadřazených modulech
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- ViliamKopecky
- Nette hipster | 230
Upravená verze Presenter::formatLayoutTemplateFiles
, která
prohledává všechny nadřazené adresáře modulů a hledá
layout
y. Třeba se to někomu bude hodit.
/**
* Formats layout template file names. Looking through each parent modules.
*
* @param string $
* @param string $
* @return array
*/
public function formatLayoutTemplateFiles($presenter, $layout)
{
$root = Environment::getVariable('templatesDir');
$presenter = str_replace(':', 'Module/', $presenter);
$module = substr($presenter, 0, (int) strrpos($presenter, '/'));
$base = '';
if ($root === Environment::getVariable('presentersDir')) {
$base = 'templates/';
if ($module === '') {
$presenter = 'templates/' . $presenter;
} else {
$presenter = substr_replace($presenter, '/templates', strrpos($presenter, '/'), 0);
}
}
$layouts = array(
"$root/$presenter/@$layout.phtml",
"$root/$presenter.@$layout.phtml",
"$root/$module/$base@$layout.phtml",
);
$modules = explode("/", $module);
for($i = count($modules) - 1;$i >= 0;$i--) {
$s = "$root/";
for($k = 0;$k <= $i;$k++)
$s .= $modules[$k] . "/$base@$layout.phtml";
$layouts[] = $s;
}
$layouts[] = "$root/$base@$layout.phtml";
return $layouts;
}
- ViliamKopecky
- Nette hipster | 230
Ještě upráva, měl jsem tam bug, a moc jsem to nekontroloval.
<?php
public function formatLayoutTemplateFiles($presenter, $layout)
{
$root = Environment::getVariable('templatesDir');
$presenter = str_replace(':', 'Module/', $presenter);
$module = substr($presenter, 0, (int) strrpos($presenter, '/'));
$base = '';
if ($root === Environment::getVariable('presentersDir')) {
$base = 'templates/';
if ($module === '') {
$presenter = 'templates/' . $presenter;
} else {
$presenter = substr_replace($presenter, '/templates', strrpos($presenter, '/'), 0);
}
}
$layouts = array(
"$root/$presenter/@$layout.phtml",
"$root/$presenter.@$layout.phtml",
);
$modules = explode("/", $module);
for($i = count($modules) - 1;$i >= 0;$i--) {
$s = "$root/";
for($k = 0;$k <= $i;$k++)
$s .= $modules[$k] . "/";
$s .= "$base@$layout.phtml";
$layouts[] = $s;
}
$layouts[] = "$root/$base@$layout.phtml";
return $layouts;
}
?>
Editoval enoice (9. 8. 2009 15:53)