views:

31

answers:

2

I am currently working on a website using, django, my problem is that the site has to be ported from using php scripts to using django. Though the site content has been well maintained by the previous maintainer, I have to use markdown for files that already having a HUGE amount of content in them, like the main page is divided into three files inside a directory, like a.html, b.html, c.html though they all contain simple text content, do I have to render them all seperately, should i use the view.py file for parsing the structure or use a template for the same, the real question is how to parse the contents of a file INSIDE the template

I wrote a template:

{% extends "catalog.html" %}

{% block content %}

{% include "features/main.html" %} {% include "features/about.html" %}

Recent Headlines

More {% include "features/1.html" %} {% include "features/2.html" %} {% include "features/3.html" %}

{% endblock %}

this is the included file i needed to parse :- {% include "features/about.html" %} but anyone will understand that this will only display the file contents not the parsed html. Thanks for the help in advance

A: 

Sorry the code is here, I dunno how it changed, but anyways:

{% extends "catalog.html" %} {% block content %} {% include "features/main.html" %} {% include "features/about.html" %}

Recent Headlines

More {% include "features/1.html" %} {% include "features/2.html" %} {% include "features/3.html" %} {% endblock %}

dart
I recommend deleting this "answer", and editing your question to include the change instead.
Joseph Spiros
A: 

The {% include %} tag only processes Django template files, and does not support any custom processing such as handling markdown in and of itself. You have a few options:

  • You can wrap all of the markdown content in the included templates with {% load markup %}{% filter markdown %} and {% endfilter %}. The filter tag applies the specified filter(s) to its contents. You will need the {% load markup %} line in the beginning of each template, as each template needs to load the additional tag libraries that it uses.
  • Your view can do the loading of the content and provide it as a context variable, so that you can do something like {{ aboutcontent|markdown }} in your template (where aboutcontent is the context variable your view provided).
    • Your view could also do the markdown conversion for you, so you'd simply have to do {{ aboutcontent }}.
  • You could write a custom templatetag that does the loading and markdown conversion for you, but that's far more complicated and you'd probably be better off with one of the other options, or simply rethinking and updating your templates to not require this processing.
Joseph Spiros
Thanks for the quick reply, the solution was to just use 'load' markup as you told and to extend that functionality into a base template which gets called from the view function, works now.
dart