0

Currently, I use the following code to include another HTML file:

{% include "machines/opennebula/resources.html" %}

I am adding another folder to add another version of resources.html (specifically to support OpenStack when I want to swap to using that cloud platform):

machines/openstack/resources.html

I want to have the path change based on whichever is set in a config file (which I incorporate into other parts of the file I'm working on using):

{{ cloudPlatform }}

I tried:

{% include "machines/{{ cloudPlatform }}/resources.html" %}

This worked when using it in association with the script tag however it hasn't worked with Django's include statement. My question is how do I make something equivalent (that works in HTML) with Django?

Alasdair
  • 298,606
  • 55
  • 578
  • 516
MRichards
  • 86
  • 1
  • 5
  • 15
  • Did that, got the following: `TemplateSyntaxError: expected token 'end of statement block', got ':'`. Also tried `{% include "machines/"|add:cloudPlatform|add:"/resources.html" %}` as per the duplicate question and still the same error. – MRichards Jan 09 '18 at 15:43
  • Made the correction, the error still occurs. Inserted a Fiddle link: https://jsfiddle.net/t0gr8528/ this includes all the code from the file (most of it is HTML, irrevelent I'm guessing when only the Django stuff is the only things needed to look at? I know little about Django, hence the inculcation of everything :) – MRichards Jan 09 '18 at 16:37
  • 1
    `{% set menufocus = "machines" %}` is not valid in Django template language. If you're using Jinja then you should have mentioned it in your question. – Alasdair Jan 09 '18 at 16:45
  • I've picked up from another codebase an apprentice had made so it may well have (I'm an apprentice myself, hence the lack of knowledge :) ). What does that mean if it is using Jinja, `|add:` won't work? Is there an alternative? – MRichards Jan 09 '18 at 16:48
  • 1
    Django supports [multiple template engines](https://docs.djangoproject.com/en/2.0/topics/templates/#module-django.template). The default is the Django template language. A common alternative is Jinja. You can check which template engines are configured in your `TEMPLATES` setting. Jinja looks similar to Django template language, but there are some differences, so I don't think `|add:` will work. – Alasdair Jan 09 '18 at 16:54
  • 1
    I understand what you're saying. Managed to find this (https://stackoverflow.com/questions/12233971/using-include-to-dynamically-point-to-html), which works for me, thanks for your help! :) – MRichards Jan 10 '18 at 09:28

0 Answers0