I'm trying to follow along with the rich text editor documentation in expression engine, but it's a little unclear to me:
http://ellislab.com/expressionengine/user-guide/development/rte_tools.html
I created a php file like this:
Class center_text {
public $info = array(
'name' => 'Center Text',
'version' => '1.0',
'description' => 'Center Aligns Text',
'cp_only' => 'y'
);
private $EE;
/**
* Constructor
*/
function __construct()
{
// Make a local reference of the ExpressionEngine super object
$this->EE =& get_instance();
}
/**
* Globals we need defined
*/
function globals()
{
$this->EE->lang->loadfile('center_text');
return array(
'rte.center_text.label' => lang('center_text')
);
}
/**
* RTE tool Definition
*/
function definition()
{
return '
WysiHat.addButton('center_text', {
label: EE.rte.center_text.label,
handler: function()
{
// Button Logic
}
});
';
}
}
// END center_text_rte class
/* End of file rte.center_text.php */
/* Location: ./system/expressionengine/third_party/center_text/rte.center_text.php */
Named and placed as mentioned in the comments. I realize that this wouldn't exactly do anything just yet (I still don't know how to make that happen) - but I would expect it to show up as an option now in the toolset of the rich text editor, but it's not.
Does anyone have an example tool they've built for the RTE, or can point me to the default tools so I can see how they're set up. All I really want to do is define some very simple styles that CMS users can apply to their text, and the css will handle the rest (such as center, left, or right aligning text).
Thanks for any help or clarification on this.
- UPDATE - -
I found the rte_tools folder in the system > expressionengine directory, and copied the "bold" example, and just changed the names to center_text, then saved to that same directory, but still nothing shows up.
Here's the revised code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author Mike Heavers
* @copyright Copyright (c) 2012, Mike Heavers
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.5
* @filesource
*/
// ------------------------------------------------------------------------
/**
* ExpressionEngine Bold RTE Tool
*
* @package ExpressionEngine
* @subpackage RTE
* @category RTE
* @author Mike Heavers
* @link http://mikeheavers.com
*/
class Center_text_rte {
public $info = array(
'name' => 'Center Text',
'version' => '1.0',
'description' => 'Centers Text',
'cp_only' => 'n'
);
private $EE;
/**
* Constructor
*
* @access public
*/
function __construct()
{
// Make a local reference of the ExpressionEngine super object
$this->EE =& get_instance();
}
// --------------------------------------------------------------------
/**
* Globals we need
*
* @access public
*/
function globals()
{
$this->EE->lang->loadfile('rte');
return array(
'rte.center_text' => array(
'add' => lang('center_text'),
'remove' => lang('remove_center_text')
)
);
}
// --------------------------------------------------------------------
/**
* JS Definition
*
* @access public
*/
function definition()
{
ob_start(); ?>
WysiHat.addButton('center_text', {
label: EE.rte.center_text.add,
'toggle-text': EE.rte.center_text.remove
});
<?php $buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
} // END Center_text_rte
/* End of file rte.center_text.php */
/* Location: ./system/expressionengine/third_party/center_text/rte.center_text.php */
$info
array is what will be used to assign a class to your button. One might make sure it matches the package name or you may have trouble getting to it with the WysiHat function.