XF 2.1 Providing data to PAGE_CONTAINER

Zig

Member
Hi everyone!

My team is currently facing an issue where a critical variable is unavailable to PAGE_CONTAINER. When checking with {{ dump($variable) }} we've found that PAGE_CONTAINER returns null, but dumping to any other template that's included in the page will return the array that we need. In this situation the custom addon in question is extending another custom addon via XFCP and we're using a code event listener---ControllerPostDispatch---to trigger the method that defines $variable. This arrangement works fine in XF1, but we've not had any luck in XF2. (It's worth noting that my predecessor implemented the class extensions in XF1 via a LoadClassController event listener instead of XFCP. I'm not sure why that was the case, but since that event isn't available in XF2, I'm using XFCP instead.)

Is there a way to feed a $variable into PAGE_CONTAINER in this scenario?

Thanks in advance!
 
You want to make use of app_setup code event listener. Something like this
PHP:
    /**
     * @param App $app
     */
    public static function appSetup(App $app)
    {
        $container = $app->container();
        
        $container['blizzard_ent_is'] = 'smol_indie_company';
    }

To make use of that in templates just call $xf.app.blizzard_ent_is.
 
Thanks for the response! Unfortunately that method breaks the entire install. "Oops! We ran into some problems," appears on every page including pages that aren't meant to be extended.
 
After rolling back I found that I'd forgotten to rebuild the addon data with the adjusted event listener. After that I got a type error that appeared to be namespace related: listenerFunction(App $app) was expecting an instance of MyCompany\OurAddon\App but receiving XF\Pub\App or XF\Admin\App instead.

It took a while to get the addon to disable (even the CLI commands failed due to the type error), but once it was disabled, I discovered the problem was with the callback. It requires a leading "XF" in order to allow all App types (Pub/Admin/Cli) to work with the Listener. I've adjusted the listener to listenerFunction(\XF\App $app) and the errors have ceased. I'm happy to report that we're now able to access the needed array in PAGE_CONTAINER! Thanks for the pointer @batpool52!!
 
Last edited:
Top Bottom