Peculiarities about template()

Peculiarities about template()

pisislerpisisler Posts: 125Questions: 24Answers: 1

I am already using a custom template for the editor form. But I need to change it for different actions. Right now, I am using template to set it initially and it works perfectly fine. But when it comes to use template(), it breaks.

Here are the peculiarities;

1- If you set template in the init options of the editor, then trying to change it later like editor.template('#template); will cause editor remove the template all together opening an empty dialog.

2- If you remove the template from init options, then you can use template() to set your custom template. But this time it works only once. If you open the editor form for the second time, again an empty dialog is what you get.

What could be I am doing wrong? What I need to do is, set a default custom template and later change it with a custom button.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Maybe this statement from the template() docs describes the problems you are seeing:

    Please note that if you overwrite an existing template node and want to be able to use it again in future, you will need to use this function as a getter initially to store it in a variable that can be reused when required. Without doing this, or inserting the element back into the document, it would be garbage collected by the browser.

    Kevin

  • pisislerpisisler Posts: 125Questions: 24Answers: 1
    edited February 2022

    I guess you are right, but I think the document is not clear enough about "how to reuse". See this example: http://live.datatables.net/lehojixi/1/edit

    I wrote custom action for the edit button just to reset the template to default. It is obvious that I am not properly "reusing" it. As I said, it's not clear how to reuse.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    Here is one option:
    http://live.datatables.net/lehojixi/2/edit

    It stores the templates into variables and uses the variables to display them.

    Kevin

Sign In or Register to comment.