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

Fixed #28190 -- Clarifed how include/extends treat template names. #8483

Merged
merged 3 commits into from Jun 3, 2017

Conversation

gitanupam
Copy link
Contributor

@gitanupam gitanupam commented May 10, 2017

I feel it is worth re-iterating that the example is using an absolute path and folks should prefix "./" if the template being referenced is in the same directory as the template that is referencing it.

https://code.djangoproject.com/ticket/28190

I feel it is worth re-iterating that the example is using an absolute path and folks should prefix "./" if the template being referenced is in the same directory as the template that is referencing it.
@@ -694,6 +694,8 @@ includes it. This example produces the output ``"Hello, John!"``:
* Template::

{% include "name_snippet.html" %}

Note that the above is referencing to an absolute path. If you need to look for ``name_snippet.html`` from the directory of the template referencing it, use ``{% include "name_snippet.html" %}``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if "absolute path" is good terminology to use, considering that the given path is usually relative to the directory specified by a template loader.

Formatting issues:

  1. Lines must be wrapped at 80 characters.
  2. This is on the same indent level as the code block and so will appear in it.
  3. I guess you meant to use "./name_snippet.html" in the example.

A clarification might be better in the discussion of relative paths in the {% extends %} tag:

A string argument may be a relative path starting with ``./`` or ``../``. For
example, assume the following directory structure::
dir1/
template.html
base2.html
my/
base3.html
base1.html
In ``template.html``, the following paths would be valid::
{% extends "./base2.html" %}
{% extends "../base1.html" %}
{% extends "./my/base3.html" %}

For example, that could be revised to say something like "A string argument may be a relative path to the current template..."

@timgraham timgraham changed the title absolute/relative paths in the 'include' templatetag example Fixed #28190 -- Clarifed how include/extends treat. template names. Jun 1, 2017
@timgraham
Copy link
Member

@gitanupam, do you want to try to amend this as suggested?

@timgraham timgraham changed the title Fixed #28190 -- Clarifed how include/extends treat. template names. Fixed #28190 -- Clarifed how include/extends treat template names. Jun 1, 2017
@gitanupam
Copy link
Contributor Author

@timgraham Done (sorry for the delay).

Added the clarification in the 'extends' section and referred to it in the 'include' example.

(was basically thinking from the mindset of the html world where including files/images/etc. are relative to the current directory by default, hence thought a clarification/reminder here might help)

@timgraham
Copy link
Member

After looking at your proposal, I thought this might be a simpler approach:

diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index daf4f9a..49375e0 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -215,8 +215,9 @@ This tag can be used in two ways:
 
 See :ref:`template-inheritance` for more information.
 
-A string argument may be a relative path starting with ``./`` or ``../``. For
-example, assume the following directory structure::
+Normally the template name is relative to the template loader's root directory.
+A string argument may also be a relative path starting with ``./`` or ``../``.
+For example, assume the following directory structure::
 
     dir1/
         template.html
@@ -674,8 +675,9 @@ This example includes the contents of the template ``"foo/bar.html"``::
 
     {% include "foo/bar.html" %}
 
-A string argument may be a relative path starting with ``./`` or ``../`` as
-described in the :ttag:`extends` tag.
+Normally the template name is relative to the template loader's root directory.
+A string argument may also be a relative path starting with ``./`` or ``../``
+as described in the :ttag:`extends` tag.
 
 This example includes the contents of the template whose name is contained in
 the variable ``template_name``::

@gitanupam
Copy link
Contributor Author

Agree - your proposal looks better.

@timgraham timgraham merged commit 1f2e4f9 into django:master Jun 3, 2017
@gitanupam gitanupam deleted the patch-1 branch June 3, 2017 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants