Jump to content

How to retrieve AllowedTemplates inside a Module


Martijn Geerts
 Share

Recommended Posts

How do I retrieve the allowed templates when hooking on processPageAdd::getAllowedTemplates ?

<?php

class AllowedTemplates extends WireData implements Module {

	public static function getModuleInfo() {
		return array(
			'title' => 'AllowedTemplates',
			'version' => 1,
			'singular' => true,
			'autoload' => true
			);
	}

	public function init() {
		$this->addHookAfter('ProcessPageAdd::getAllowedTemplates', $this, "allowedTemplates");
	}

	public function allowedTemplates($event) {
		
		$pid = wire("input")->parent_id;
		if(!(int)$pid) return;
		$parent = wire("pages")->get($pid);
		if(!$parent->id) return;
            
                // should be made dynamic, but I don't know how to retreive the templates array !!!

		$templates = wire('templates')->find("name=basic-page|sitemap");
		$event->return = $templates;
	}
}

Link to comment
Share on other sites

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...