1
votes

I am building a custom image insert plugin for TinyMCE. The idea is that each article already has a relationship with a collection of images through an ArticleImage model which allows the user to provide an article-specific caption. The TinyMCE will then insert a custom tag (something like <myapp:image image-id="9389" caption="Caption override">) which is rendered as a preview of the image and caption in the editor, and rendered into <figure><img src="images/9389.jpg" /><figcaption>Caption override (Photo: photographer)</figcaption></figure>. This could equally be something like <myapp:poll> or <myapp:video>.

My question is: what is the best way (and where is the best place) to parse this 'dummy tag' into its rendered HTML in the Django view?

Or is there another, better approach?

1

1 Answers

1
votes

IMHO, the best place to render custom markup, is in the template via a templatefilter.

I would risk myself to say that using a templatefilter to render custom markup is the "djangoish" way, since that's the way to go with django.contrib.markup.

Storing the custom tag in the model is a good idea, because then you can change the template filter implementation, which would be impossible if the custom tag is processed before storage.