Add WYSIWYG editor to Prestashop 1.6.X module smarty template form

4.4k views Asked by At

I am doing a custom module in Prestashop 1.6.X. In my module I have form which is made in smarty. I want to add WYSIWYG editor in that smarty form. So can someone tell me how to add WYSIWYG editor to smarty template form? Any help or suggestion will be really appreciable. Thanks

1

There are 1 answers

6
timactive On

You have many solution to indicate if element in your Form have wysiwyg editor. If you use helperform you can use this solution :

Solution backoffice / use helper form

$fields_form[0]['form'] = array (
            'input' => array (
                array (
                    'type' => 'textarea',
                    'label' => $this->l ( 'Your field:' ),
                    'name' => 'pdf_content',
                    'autoload_rte' => true,
                    'required' => true,
                    'lang' => true,
                    'rows' => 10,
                    'cols' => 100,
                    'hint' => $this->l ( 'Invalid characters:' ).' <>;=#{}'
                ),
****
$helper = new HelperForm ();
****
$helper->generateForm ( $fields_form )

Second solution in your template :

Example in yourmodule.php function getContent

public function getContent()
    {

$iso = $this->context->language->iso_code;
                                $this->tpl_vars['iso'] = file_exists(_PS_CORE_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en';
                                $this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
                                $this->tpl_vars['ad'] = __PS_BASE_URI__.basename(_PS_ADMIN_DIR_);
                                $this->tpl_vars['tinymce'] = true;

                                $this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
                                $this->context->controller->addJS(_PS_JS_DIR_.'admin/tinymce.inc.js');

in your smarty template file :

<script type="text/javascript">
    var iso = '{$iso|escape:'quotes':'UTF-8'}';
    var pathCSS = '{$smarty.const._THEME_CSS_DIR_|escape:'quotes':'UTF-8'}';
    var ad = '{$ad|escape:'quotes':'UTF-8'}';
    $(document).ready(function(){


            tinySetup({
                editor_selector :"autoload_rte",
                relative_urls : false,
                plugins : "colorpicker link image paste pagebreak table contextmenu filemanager table code media autoresize textcolor fullpage",
                extended_valid_elements : "em[class|name|id],html,head"
            });


    });
</script>

<textarea name="content_html" class="rte autoload_rte rte autoload_rte">your text rich</textarea>