Hallo, ich hab ein Modul, welches 2 Templates hat. Ich kann die Templates bei den Modulen im Backend auch auswählen und zuordnen. Das funktioniert.
Im Backend habe ich bei der Eingabemaste meiner Daten 2 Felder. Die Felder heißen "alle" und "compliance"
Jetzt möchte ich, dass je nach Feld das richtige Template angesprochen wird, und hier stecke ich fest.
aktuell wird immer das Template angesprochen, weche unter $strTemplate eingetragen ist. In den Templates selbst habe ich eine IF-Anweisung, wo ich das Feld "alle" bzw. "compliance" abfrage. Für's Frontend hab ich dafür 2 Module eingebunden, mit dem jeweiligen Template.
PHP-Code:
namespace Steinkellner\Webmails;
class ModuleWebmailList extends \Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'webmail_list_all';
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['webmail'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
return parent::generate();
}
/**
* Compile the current element
*/
protected function compile()
{
global $objPage;
\System::loadLanguageFile('tl_webmail');
$webmailCount = \WebmailModel::findAllByPublished();
$rows = array();
while($webmailCount->next())
{
$rows[] = $webmailCount->row();
}
$total = \count($rows);
$limit = $total;
$offset = 0;
// Pagination
if ($this->perPage > 0)
{
$id = 'page_e' . $this->id;
$page = Input::get($id) ?? 1;
if ($page < 1 || $page > max(ceil($total/$this->perPage), 1))
{
throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
}
$offset = ($page - 1) * $this->perPage;
$limit = min($this->perPage + $offset, $total);
$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id);
$this->Template->pagination = $objPagination->generate("\n ");
}
/**
* Abfragen der Tabelle
**/
$webmails = array();
$result = \WebmailModel::findAllByPublished();
while ($result->next())
{
$webmails[] = array
(
'title' => \StringUtil::specialchars($result->title),
'url' => htmlspecialchars($result->url),
'alle' => $result->alle,
'compliance' => $result->compliance,
'date' => $result->date
);
}
//Template
$this->Template->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['tl_webmail']['header_title']);
$this->Template->date = \StringUtil::specialchars($GLOBALS['TL_LANG']['tl_webmail']['header_date']);
$this->Template->webmails = $webmails;
}
}
Lesezeichen