Skip to content

File Structure

Q edited this page Aug 17, 2020 · 20 revisions

The location and structure of certain files are very important to how Willow works, so understanding the lookup process is equally important.

Data is gathered greedily, but merged logically - Willow out-of-the-box will search for configuration settings within itself, with the Q plugin, a parent or child theme - in that order and will merge all collected data, prioritizing the later over the former, while trying to ensure that all required configuration are present - from the simple base model found in the file library/view/context/global.php

@todo...

Parent / Child

By default, child theme data is loaded over parent, following the standard priority of both Willow and WordPress - however, it is also possible to carry both child and parent theme data inside the parent theme ( useful in cases where the parent theme acts as a reusable template ) by adding the following file structure to the parent theme:

base directory library/view/

  • parent
    • post.willow
  • child
    • post.willow

This set-up may not work for many, nor make sense to all, but used correctly, it allows parent themes to define settings for child themes, which "might" one day move to the child theme itself...

Extending lookup locations

As Willow contexts can be extended, it is also required to allow plugins to extend the configuration lookup locations, this can be achieved by adding the lookup parameters to the context extension callback, as shown in the following example:

public static function __run() {
	
	// check for willow ##
	if( ! class_exists( 'q_willow' ) ){ return false; }

	$class = new \ReflectionClass( __CLASS__ );
	$methods = $class->getMethods( \ReflectionMethod::IS_PUBLIC );
	foreach( $methods as $key ){ $public_methods[] = $key->name; } // match format returned by get_class_methods() ##

	// register new class methods ##
	\add_action( 'after_setup_theme', function() use ( $public_methods ) {
		\q\willow\context\extend::register([ 
			'context' 	=> 'user',#str_replace( __NAMESPACE__.'\\', '', __CLASS__ ), 
			'lookup'	=> \q_user::get_plugin_path( 'library/view/context/' ), // allow for extended .willow lookups ##
			'class' 	=> __CLASS__,
			'methods' 	=> $public_methods // public only 
		]);
	}, 2 );

}

In this example, we are telling Willow to also look in the path library/view/context/ when running checks for willow configuration files.

Clone this wiki locally