Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple template tag to render the editor #135

Open
ghost opened this issue Sep 1, 2020 · 1 comment
Open

Simple template tag to render the editor #135

ghost opened this issue Sep 1, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 1, 2020

Hi all, I've a template which rather than using forms, calls an API directly. I'd like to include the martor editor in the page. Is there a simple way of inserting something like {{ martorfield }} into the middle of some form html to add the markdown editor with a relevant html form element name?

@agusmakmun
Copy link
Owner

agusmakmun commented Mar 29, 2024

Hello @ghost, seems currently we didn't support this yet.
But, I'll give you some clues how to do it manually in your project.

  1. Create the custom martor templatetags to convert the original textarea to div+textarea from martor, for example:
from django import template
from martor.widgets import MartorWidgetregister = template.Library()

@register.filter
def as_martor_field(form_textarea):
    return MartorWidget‎().render(name=form_textarea.name, value=form_textarea.value)
  1. And use it in your template as:
{{ field.description|as_martor_field }}
  1. In your template, don't miss to add the static files to ensure the editor loaded correctly, example: https://github.com/agusmakmun/django-markdown-editor/blob/master/martor_demo/app/templates/bootstrap/form.html

Note: above code is just exploration, and didn't test yet. Just give an idea how to do it.


But, to note that adding more template tags will consume more on memory/ram.
So, I suggest you to do it via forms or models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant