• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

[GUIDE] Adding the Editor Template to your Mod!

Jaxel

Well-known member
My god I love XenForo... adding the editor template to your mod couldn't possibly be any easier.

In your action function there should be a similar code to whats below. It wont be the same, since everyone's mod file names and naming structure are different.
Code:
return $this->responseView('MyAddon_ViewPublic_Edit', 'MyAddon_Edit', $viewParams);

As you should know by now, 'MyAddon_ViewPublic_Edit' is the unique ViewPublic class for your page, and 'MyAddon_Edit' is the name of the template the responseView will load up when processing your function. Somewhere in your 'MyAddon_Edit' template should be the following code. Wherever you put it, thats where your editor will be:
Code:
{xen:raw $editorTemplate}

The the last thing we must do is create the hook which will add the $editorTemplate to your parameters. Its simple, create a class in '/library/MyAddon/ViewPublic/Edit.php' with the following code.
Code:
<?php

class EWRporta_ViewPublic_Edit extends XenForo_ViewPublic_Base
{
	public function renderHtml()
	{
		$this->_params['editorTemplate'] = XenForo_ViewPublic_Helper_Editor::getEditorTemplate(
			$this, 'message', $this->_params['defaultMessage']
		);
	}
}

If you would like there to be a default message (such as if you are editing a page), you simply need to rename 'defaultMessage' to an existing parameter within your page. For instance, to use the $page['page_content'] variable, I changed it as follows:
Code:
$this->_params['page']['page_content'];

Remember! I'm an unemployed programmer who enjoys donations!
 
Excellent job :) I have a few questions about this. When I have more time tomorrow, I might give you a poke on IRC. :)
 
New things to add... if you want to disable the WYSIWYG editor in a text field... use this code:
Code:
<?php

class EWRporta_ViewPublic_Tedit extends XenForo_ViewPublic_Base
{
	public function renderHtml()
	{
		$this->_params['editorTemplate'] = XenForo_ViewPublic_Helper_Editor::getEditorTemplate(
			$this, 'message', $this->_params['template']['template_content'], array('disable' => true)
		);
	}
}
Notice the ", array('disable' => true)" at the end.


If you want to retrieve the contents of the text editor, use this code:
Code:
		$input['message'] = $this->getHelper('Editor')->getMessageText('message', $this->_input);
		$input['message'] = XenForo_Helper_String::autoLinkBbCode($input['message']);
You can then access it using $input['message']...


you can rename 'message' by replacing the text in the fields in the two above codes.
 
I'm trying to run this code, but when pressing the button, I get "undefined" in my alert box, even though I have text inside my editor.
What am I doing wrong? :(

Code:
<script type="text/javascript">
function getText()
{
var x = tinyMCE.get('Editor');
alert(x); // should output "object [Object]" in FF
alert(x.getContent); // should output function code
alert(x.getContent()); // should output a string
}
</script>
 
Top Bottom