Jump to content

Template Data Providers: Adding persistent variables to page object before rendering


felix
 Share

Recommended Posts

There currently is an issue with the "Template Data Providers" Module which prevents variables that are set within the "dataprovider" files (controllers) are accessible in the template later.

The module works like this: For every template you create a file that handles fetching and manipulating data (doing "business logic"). The files look like this:

<?php

class HomePage extends \nw\DataProviders\PageDataProvider {

	public function populate() {

		$this->foo = 'bar';

	} 
}

foo from there should be available as $foo within the template. This worked until 2.3 but seems to be broken now.  

The module Hooks to beforePageRender and executes the populate() method where the variables are set:

https://github.com/marcostoll/processwire-template-data-providers/blob/master/TemplateDataProviders.module#L147

I tracked down the issue to the core module "PageRender" ( https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/PageRender.module#L305 ) where $page->output(true) is called and creates a fresh copy of the Page object. At this point all variables that were added get lost because they aren't persisted.

Any Ideas how to avoid this?

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...