Search code examples
javascriptckeditor

CKEditor Custom Properties Not Working and Getting Error


I am fairly new to CKEdtior and have just installed it on this website I'm working on, the version is 4.4.4

The editor itself loads into the page, but custom properties like language or uiColor aren't working, and with or without properties, I keep getting the error:

Uncaught TypeError: Cannot read property 'getEditor' of undefined

I know I'm doing something wrong, because it works in the samples. If it helps, the code is part of a Smarty template. I tried using an ID that doesn't have an underscore, and of course checking in different browsers—the error appears in IE, FF and Chrome.

Relevant bits of code:

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    {literal}
    CKEDITOR.replace( 'show_description',
    {
        language: 'he'
    });
    {/literal}
</script>

<textarea name="show_description" id="show_description" class="ckeditor"></textarea>

Solution

  • You cannot call CKEDITOR.replace() before the place where the relevant <textarea> is in the code. You can see this in the replace by code sample:

    <textarea cols="80" id="editor1" name="editor1" rows="10">content</textarea>
    <script>
    
        // This call can be placed at any point after the
        // <textarea>, or inside a <head><script> in a
        // window.onload event handler.
    
        // Replace the <textarea id="editor"> with an CKEditor
        // instance, using default configurations.
    
        CKEDITOR.replace( 'editor1' );
    
    </script>