0

So, I am trying to load a template based on the current URL, and

For example:

{% if 'foo/bar/gallery' in request.path %}
    {% include 'web/custom/foo/bar/gallery.html' %}
{% endif %}

The foo/bar/ is dynamic, as are the directory template locations. The string 'gallery' will always be the same, and can be hardcoded if that matters. How can this be achieved?

FYI: still on django 1.3.7

nfq
  • 113
  • 8
  • Possible duplicate of [this question](http://stackoverflow.com/questions/4386168/how-to-concatenate-strings-in-django-templates/23783666#23783666) – Alasdair Nov 07 '16 at 16:16

1 Answers1

1

I think that you should avoid the logic in the template. I suggest 2 options :

  • Prepare the name of the template in your view
  • Or, create a template tags so you can deal with the logic outside the template.
martync
  • 350
  • 4
  • 15
  • 1
    Thanks @martync. It will probably have to be a template tag then, as there is a big collection of 'gallery' templates (one per URL) that need to be included, so wanting to avoid hardcoding each template name in the view. I'll try and figure this out with a template tag then. Pretty new to Django... – nfq Nov 07 '16 at 16:53
  • I'm struggling with this, as I'm a bit of a Django noob. Would you be able to help me further? Or do you have any ideas where one can find freelance help? – nfq Nov 30 '16 at 15:23