How to get to extra field content inside the "notice" template

Rob

Well-known member
I've added an extra field to the xf_notice table, however, the extra field doesn't appear to be available inside the "notice" template using $notice.extraField

If I add an extra field to the forum template, it's automatically available to most templates that use $forum so why is this extra field not available in the $notice var inside the "notice" template?

Ideas?
 
Hmmm.... there is caching going on here so I've extended the rebuildNoticeCache() and getDefaultNotice() inside the model to include the extra field.
Still no extra field coming through to the template though. :(

Am I doing this function properly? Does it need to call the parent or something?

PHP:
<?php

class MyNotices_Model_Notice extends XFCP_MyNotices_Model_Notice
{
    public function rebuildNoticeCache()
    {
        $cache = array();

        foreach ($this->getAllNotices() AS $noticeId => $notice) {
            if ($notice['active']) {
                $cache[$noticeId] = array(
                    'title' => $notice['title'],
                    'message' => $notice['message'],
                    'dismissible' => $notice['dismissible'],
                    'wrap' => $notice['wrap'],
                    'user_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['user_criteria']),
                    'page_criteria' => XenForo_Helper_Criteria::unserializeCriteria($notice['page_criteria']),
                    'extraField' => $notice['extraField']
                );
            }
        }

        $this->_getDataRegistryModel()->set('notices', $cache);
        return $cache;
    }

    public function getDefaultNotice()
    {
        return array(
            'notice_id' => 0,

            'title' => '',
            'message' => '',

            'user_criteria' => '',
            'userCriteriaList' => array(),

            'page_criteria' => '',
            'pageCriteriaList' => array(),

            'active' => 1,
            'dismissible' => 1,
            'display_order' => 1,
            'wrap' => 1,
            'extraField' => '',
        );
    }
}
 
Last edited:
I've inspected the cache in the dataregistry and my extra fields are there.... why on earth are they not coming back to the notice template in the front end? grrrrrrrr
 
Ok, now I can see why this is not working.

@Mike, after the notices_prepare event is fired (inside ViewRenderer/HtmlPublic.php -> _getNoticesContainerParams), the $notices array is then built, but with hard-coded fields.
Could the event fire after the array is built so that developers can add additional fields to notices?

Meanwhile, which code event can I listen to to override ViewRenderer/HtmlPublic.php?
 
Back
Top Bottom