Jump to content

Templatelist Inside Module Configuration


Recommended Posts

Hi there,

Is there a way to get:

foreach($templates as $template){
 $options.= "<li>{$template->name}</li>";
}
to work for a selectbox inside "getModuleConfigInputfields"?
 
i am implementing a module which hooks after page->save.
 
i need the Values (Parent Template, Child Template, Child number, Child name) to be set.
I would rather do this with a selectbox of all Templates then with a Textfield.
 
idea behind this is that a customer should be able create a page and gets always the same amount of children inside the page, which should be configurable on the module, because i need this similar tool already 3 times.
 
 
thanks for every help
Link to comment
Share on other sites

okay found a way myself :

foreach(wire('templates') as $template){
	$field->addOption($template->name, $template->name);
}

hint: i found it in AdminThemeDefualtHelpers.php

if anyone needs this feel free to copy :)

public static function getModuleConfigInputfields(array $data){
		$inputfields = new InputfieldWrapper();

		//--Parent Template
		$field = wire('modules')->get('InputfieldSelect');
		$field->attr('name', 'parent_template');
		$field->label = __('Parent Template');

		foreach(wire('templates') as $template){
			$field->addOption($template->name, $template->name);
		}
		$field->attr('value', isset($data['parent_template']) ? $data['parent_template'] : '');
		$inputfields->add($field);

		//--Child Template
		$field = wire('modules')->get('InputfieldSelect');
		$field->attr('name', 'child_template');
		$field->label = __('Child Template');

		foreach(wire('templates') as $template){
			$field->addOption('$template->name', $template->name);
		}
		$field->attr('value', isset($data['child_template']) ? $data['child_template'] : '');
		$inputfields->add($field);

		//--Child Name
		$field = wire('modules')->get('InputfieldText');
		$field->attr('name', 'child_name');
		$field->label = __('Child Name');
		$field->attr('value', isset($data['child_name']) ? $data['child_name'] : '');
		$inputfields->add($field);

		//--Children to Create
		$field = wire('modules')->get('InputfieldInteger');
		$field->attr('name', 'child_number');
		$field->label = __('Childs to Create');
		$field->attr('value', isset($data['child_number']) ? $data['child_number'] : '');
		$inputfields->add($field);

		return $inputfields;
	}
  • Like 4
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

×
×
  • Create New...