Para esas soluciones que nunca recuerdas
Joomla: function to get template positions
We needed a function to get available template positions. Didn’t found lot of info out there so we created our own function.
/**
* Parse templateDetails.xml and get available positions
* @author Jiden - Digital Disseny, S.L.
* @version 04/04/2012
*
* @param string $tplPath - path of the current theme
* @param boolean $nameAsKey - set position name as output array key?
*
* @return array of positions
*/
function getTplPositions($tplPath, $nameAsKey = false) {
$outputArray = array();
$templateXML = $tplPath.'/templateDetails.xml';
// try to load positions from template XML file
$xml = JFactory::getXML($templateXML);
if (is_object($xml)) {
$positions = $xml->xpath('positions/position');
if ($positions) {
foreach ($positions as $position) {
$name = (string)$position->data();
// clean name
$name = preg_replace("/(\-a|\-b|\-c|\-d|\-e|\-f)$/i", "", $name);
// do not add duplicates
if(!in_array($name, $outputArray)) {
// use position name as array key?
if($nameAsKey) $outputArray[$name] = $name;
else $outputArray[] = $name;
}
}
}
}
return $outputArray;
}
Now you can use the function as:
$tplPath = JPATH_SITE . '/templates/' . $this->template; $positions = getTplPositions(); print_r($positions);
That will return something like:
Array
(
[0] => debug
[1] => header-top
[2] => header
[3] => header-bottom
[4] => topmenu
[5] => rsidebar-top
[6] => rsidebar
[7] => rsidebar-bottom
[8] => lsidebar-top
[9] => lsidebar
[10] => lsidebar-bottom
[11] => main-top
[12] => main
[13] => main-bottom
[14] => component-top
[15] => component
[16] => component-bottom
[17] => footer-top
[18] => footer
[19] => footer-bottom
Deja un comentario