maty321
04-09-2012, 18:48
Chcę aby szablon wpisu (tylko wpisu, nie kategoria) w K2 był zależny od jednego z dodatkowych pól. Mam przy dodawaniu artykułu np pole "szablon" z wyborem dwóch opcji "opcja1" "opcja2" jeśli wybiorę opcje 1 ma być zastosowany szablon1...
w pliku components\com_k2\views\item\view.html.php edytowałem fragment kodu odpowiedzialny za szablon:
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.$item->params->get('theme'));
$extrafields = array();
foreach($item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
$szablon = $extrafields[1]; // 1 to id pola
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.$item->params->get('theme'));
if ( $szablon == 'opcja1')
{
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'szablon1');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.'szablon1');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'szablon1') ;
}
if ($szablon == 'opcja2')
{
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'szablon2');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.'szablon2');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'szablon2') ;
}
Mam jednak problem bo wyświetla się wyłącznie biała strona, zawartość pola pobieram poprawnie ponieważ gdy dodam echo $extrafields[1] wyświetli mi się poprawna zawartość. Może ktoś na tym forum wie jak można coś takiego zrobić aby działało poprawnie :)
w pliku components\com_k2\views\item\view.html.php edytowałem fragment kodu odpowiedzialny za szablon:
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.$item->params->get('theme'));
$extrafields = array();
foreach($item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
$szablon = $extrafields[1]; // 1 to id pola
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.$item->params->get('theme'));
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.$item->params->get('theme'));
if ( $szablon == 'opcja1')
{
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'szablon1');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.'szablon1');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'szablon1') ;
}
if ($szablon == 'opcja2')
{
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'szablon2');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates' .DS.'szablon2');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'szablon2') ;
}
Mam jednak problem bo wyświetla się wyłącznie biała strona, zawartość pola pobieram poprawnie ponieważ gdy dodam echo $extrafields[1] wyświetli mi się poprawna zawartość. Może ktoś na tym forum wie jak można coś takiego zrobić aby działało poprawnie :)