protected function insertIntoTemplate ($template, $field, $reference = null, $after = true)
	{
		$template = $this->getTemplate($template);
		$fieldgroup = $template->fieldgroup;
		$method = $after ? 'insertAfter' : 'insertBefore';

		$field = $this->getField($field);

		// Get reference if supplied
		if($reference instanceof Field)	
			$reference = $fieldgroup->get($reference->name);
		else if(is_string($reference))  
			$reference = $fieldgroup->get($reference);

		// Insert field or append
		if($reference instanceof Field)
			$fieldgroup->$method($field, $reference);
		else 
			$fieldgroup->append($field);

		$fieldgroup->save();
	}
protected function insertIntoTemplate ($template, $field, $reference = null, $after = true)
	{
		$template = $this->getTemplate($template);
		$fieldgroup = $template->fieldgroup;
		$method = $after ? 'insertAfter' : 'insertBefore';

		$field = $this->getField($field);

		// Get reference if supplied
		if($reference instanceof Field)	
			$reference = $fieldgroup->get($reference->name);
		else if(is_string($reference))  
			$reference = $fieldgroup->get($reference);

		// Insert field or append
		if($reference instanceof Field)
			$fieldgroup->$method($field, $reference);
		else 
			$fieldgroup->append($field);

		$fieldgroup->save();
	}
protected function insertIntoTemplate ( $ template , $ field , $ reference = null , $ after = true ) { $ template = $ this -> getTemplate ( $ template ) ; $ fieldgroup = $ template -> fieldgroup ; $ method = $ after ? 'insertAfter' : 'insertBefore' ; $ field = $ this -> getField ( $ field ) ; // Get reference if supplied if ( $ reference instanceof Field ) $ reference = $ fieldgroup -> get ( $ reference -> name ) ; else if ( is_string ( $ reference ) ) $ reference = $ fieldgroup -> get ( $ reference ) ; // Insert field or append if ( $ reference instanceof Field ) $ fieldgroup -> $ method ( $ field , $ reference ) ; else $ fieldgroup -> append ( $ field ) ; $ fieldgroup -> save ( ) ; }
Insert a field into a template optionally at a specific position.

@param Template|string   $template
@param Field|string      $field
@param Field|string|null $reference
@param bool              $after
@throws WireException
Insert a field into a template optionally at a specific position .