XF 1.5 Passing Var To Additional Templates

king8084

Well-known member
I'm attempting to implement a workaround to this known bug.

Essentially, xf utilizes $visitor.alerts_unread instead of $alertsUnread in 'navigation_visitor_tab' when displaying the number of unread alerts.

The value stored in $visitor.alerts_unread can become incorrect over time, as unread alerts get purged after 30 days (hard-coded in Alerts.php); $visitor.alerts_unread stores the value of unread alerts without accounting for the alerts that are no longer accessible (ones that fall outside of the 30-day limit). The value stored in $alertsUnread contains the correct value that should be displayed. That var, however, is only accessible in 'account_alerts_popup'.

$alertsUnread is set in public function actionAlertsPopup() in Account.php and returned via:

Code:
        return $this->responseView(
            'XenForo_ViewPublic_Account_AlertsPopup',
            'account_alerts_popup',
            $viewParams
        );

...how can i utilize $alertsUnread in a template outside of 'account_alerts_popup'? either via an edit to the Account.php file, or via a handoff inside of the templates (var container didn't seem to work and i'm unaware of an alternate). i'm not awesome at php edits quite yet, so might need a little coaching if done there.
 
Last edited:
$alertsUnread is set in public function actionAlertsPopup() in Account.php
Well, do the same in the other method you want to access $alertsUnread. There's a process behind the creation of $alertsUnread, you would need to copy that.
Another option could be to write and execute a raw query and pass the result to the template. But I guess there is a function already to get current unread alerts.
 
Back
Top Bottom