Cupara
Well-known member
I'm having issues, I need to pass a foreach to a template that I include in my sublink template.
The problem is I can't get any template listeners to work and I can't get a hook to work I added to my own template.
Any suggestions?
Template with include:
Contents of included template:
Listener file (Tried using Ragtek's method also includes my custom template hook):
ControllerIndex where $label is defined:
The problem is I can't get any template listeners to work and I can't get a hook to work I added to my own template.
Any suggestions?
Template with include:
HTML:
<ul class="secondaryContent blockLinksList">
<xen:hook name="nr_links_end">
<li><a href="{xen:link 'news'}">All</a></li>
</xen:hook>
</ul>
Contents of included template:
HTML:
<li>{xen:raw $label}</li>
Listener file (Tried using Ragtek's method also includes my custom template hook):
PHP:
class NewsReader_Listener_Vars
{
public static function createTemplate(&$templateName, array &$params, XenForo_Template_Abstract $template)
{
if($templateName == 'nr_links') {
$template->preloadTemplate('nr_prefix_links');
}
}
public static function template($name, &$contents, array $params, XenForo_Template_Abstract $template)
{
if ($name == 'nr_links_end')
{
$templateParams = $template->getParams();
$search = '</ul>';
$params = array(
'selectedKey' => $templateParams['selectedKey']
);
$prefixLinks .= $template->create('nr_prefix_links')->render();
$contents = str_replace($search, $prefixLinks, $contents);
}
}
}
ControllerIndex where $label is defined:
PHP:
<?php
class NewsReader_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
// Prepare to grab any options needed
$options = XenForo_Application::get('options');
// Build the public link
$this->canonicalizeRequestUrl(
XenForo_Link::buildPublicLink('news', null)
);
// Build the Model for caching
$feedModel = $this->getModelFromCache('NewsReader_Model_Feed');
// Unique for testing only.
$visitor = XenForo_Visitor::getInstance();
$visitor_id = $visitor->getUserId();
$userName = $visitor['username'];
// Lets paginate the results
$page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
$perPage = $options->nr_limit;
$allFeeds = $feedModel->getFeedLog(array('perPage' => $perPage, 'page' => $page));
$count = $feedModel->getFeedAllCount();
//$title = new XenForo_Phrase('thread_prefix_');
//$prefixId = $allFeeds['prefix_id'];
// Grab the data
//$prefixGroup = $feedModel->getPrefixGroupById();
/*foreach ($prefixGroup AS $prefix)
{
$title = new XenForo_Phrase('thread_prefix_' . $allFeeds['prefix_id']);
$label = '<li><a href="{xen:link \'news/prefix/\', $title}">{xen:raw $title}</a></li>';
}*/
$feed = array();
foreach ($allFeeds AS $feeds)
{
$prefix = new XenForo_Phrase('thread_prefix_' . $feeds['prefix_id']);
if (!$feeds['prefix_id'])
{
$feed[] = '<li style="border-bottom:1px solid #cecfd0;padding-left:3px;line-height:20px;"><a href="javascript:frameSrc(\''. $feeds['unique_id'].'\'); var waste = \'/threads/\';">'. $feeds['title'] .'</a><span style="float:right;"><a href="threads/'. $feeds['thread_id'] .'/reply">Comment</a></span></li>';
} else {
$feed[] = '<li style="border-bottom:1px solid #cecfd0;padding-left:3px;line-height:20px;">['.$prefix.'] <a href="javascript:frameSrc(\''. $feeds['unique_id'].'\'); var waste = \'/threads/\';">'. $feeds['title'] .'</a><span style="float:right;"><a href="threads/'. $feeds['thread_id'] .'/reply">Comment</a></span></li>';
}
}
$label = "Test";
// Register for use in the template
$viewParams = array(
'count' => $count,
'page' => $page,
'perPage' => $perPage,
'username' => $userName,
'visitor_id' => $visitor_id,
//'feeds' => $allFeeds,
//'prefixGroup' => $prefixGroup,
'prefix' => $prefix,
//'data' => $data,
'feed' => $feed,
'feeds' => $feeds,
'label' => $label
);
return $this->responseView('NewsReader_ViewPublic_News', 'nr_index', $viewParams);
}