How can I get a Django Template to render itself within a Mako Template? -


We decided to use Mako Templates in our Django project a while ago. We are supporting Django templates due to reusable apps (obviously), it is believed that Django Templating is available. I found it possible to present Jaguango templates from Maco, but I have not found any way to work it in another way.

The list of app I have just added for us, and it uses Django templating It seems that the base.html file is an override Django Template. Unfortunately, our main site is built using Maqo, so far I can not understand Geno templates within Mako for a host in a clean way.

I think that I want to be a template tag that will call Maaka and request to be 'embedded'.

Our Mac templates currently do the following:

  & lt;% inheritance file = "mako / base.html" / & gt;   

What do I want to be able to do something like this from a blueprint:

  {% render_in_mako 'mako / base.html' '' Body '%}' with the following in 'Mako / base.html'   

:

  & lt; / Head & gt; & Lt; Body & gt; & Lt;% include file = "header.html" /> $ {Next.bd ()} & lt; / Body & gt; & Lt; / Html & gt;   

Has anyone had to do this before? I'm not so familiar with writing template tags do you think it can be done? Alternatively it is possible to rewrite all templates in Maco, and it does not appeal to me at all. A template tag would be incredibly useful for many incredible projects I think are using Mako.

Good question! A Mako template can be provided within the Django template, thanks to Django. Django documents explain this process in more detail, but basically you have to parse the input of the tag, make sure the arguments are valid, and create a django.template.Node object from it. node is an object that takes your template tag arguments and defines a render () method to process them. However, you have to be careful to avoid your template tag return text in particular, because you definitely can not survive the HTML tag. Apparently the Django people have also considered this, and in the same document there is a section that tells how to do it.

Once you understand how to parse the input from the template tag (which is actually just to validate the arguments), you can specify the rendering of Mako with the template and references given in the tag To call the function, call . You can define the render () method, and return the output to the degena templates. I was a little confused with your description, however, when you used 'body' as a second argument, what does it mean, is it relative to the template? I have to admit that I have not used Mako, but a quick look at the document shows that there are similarities to the Déjengo and Jinja 2 systems; I apologize if this assumption is wrong. If you can make it through the Denggo template tag docs, it sounds like a proper venture.

Comments