From 6eae465e64635e671693ea7d1af0b819eb7d9ced Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 13 Oct 2015 09:52:16 +0100 Subject: [PATCH] Renamed "self" template variable to "page" in docs --- docs/advanced_topics/i18n/duplicate_tree.rst | 12 +++---- docs/advanced_topics/i18n/index.rst | 4 +-- docs/advanced_topics/privacy.rst | 2 +- docs/getting_started/tutorial.rst | 36 ++++++++++---------- docs/reference/contrib/forms.rst | 10 +++--- docs/reference/contrib/routablepage.rst | 6 ++-- docs/reference/contrib/staticsitegen.rst | 4 +-- docs/reference/pages/model_recipes.rst | 12 +++---- docs/topics/images/using_in_templates.rst | 28 +++++++-------- docs/topics/pages.rst | 4 +-- docs/topics/snippets.rst | 4 +-- docs/topics/streamfield.rst | 16 ++++----- docs/topics/writing_templates.rst | 12 +++---- 13 files changed, 75 insertions(+), 75 deletions(-) diff --git a/docs/advanced_topics/i18n/duplicate_tree.rst b/docs/advanced_topics/i18n/duplicate_tree.rst index 3c6f7be2aa..010f18e91f 100644 --- a/docs/advanced_topics/i18n/duplicate_tree.rst +++ b/docs/advanced_topics/i18n/duplicate_tree.rst @@ -131,14 +131,14 @@ You can make use of these methods in your template by doing: .. code-block:: html+django - {% if self.english_page and self.get_language != 'en' %} - {% trans "View in English" %} + {% if page.english_page and page.get_language != 'en' %} + {% trans "View in English" %} {% endif %} - {% if self.french_page and self.get_language != 'fr' %} - {% trans "View in French" %} + {% if page.french_page and page.get_language != 'fr' %} + {% trans "View in French" %} {% endif %} - {% if self.spanish_page and self.get_language != 'es' %} - {% trans "View in Spanish" %} + {% if page.spanish_page and page.get_language != 'es' %} + {% trans "View in Spanish" %} {% endif %} diff --git a/docs/advanced_topics/i18n/index.rst b/docs/advanced_topics/i18n/index.rst index e2001c060e..2a7c7e507e 100644 --- a/docs/advanced_topics/i18n/index.rst +++ b/docs/advanced_topics/i18n/index.rst @@ -198,9 +198,9 @@ Finally, in the template, reference the accessors instead of the underlying data .. code-block:: html+django - {{ self.translated_title }} + {{ page.translated_title }} - {{ self.body }} + {{ page.body }} Other approaches diff --git a/docs/advanced_topics/privacy.rst b/docs/advanced_topics/privacy.rst index eeb03a5244..4f59b6b922 100644 --- a/docs/advanced_topics/privacy.rst +++ b/docs/advanced_topics/privacy.rst @@ -17,7 +17,7 @@ By setting ``PASSWORD_REQUIRED_TEMPLATE`` in your Django settings file, you can PASSWORD_REQUIRED_TEMPLATE = 'myapp/password_required.html' -This template will receive the same set of context variables that the blocked page would pass to its own template via ``get_context()`` - including ``self`` to refer to the page object itself - plus the following additional variables (which override any of the page's own context variables of the same name): +This template will receive the same set of context variables that the blocked page would pass to its own template via ``get_context()`` - including ``page`` to refer to the page object itself - plus the following additional variables (which override any of the page's own context variables of the same name): - **form** - A Django form object for the password prompt; this will contain a field named ``password`` as its only visible field. A number of hidden fields may also be present, so the page must loop over ``form.hidden_fields`` if not using one of Django's rendering helpers such as ``form.as_p``. - **action_url** - The URL that the password form should be submitted to, as a POST request. diff --git a/docs/getting_started/tutorial.rst b/docs/getting_started/tutorial.rst index 45839fa5ea..cf9991199e 100644 --- a/docs/getting_started/tutorial.rst +++ b/docs/getting_started/tutorial.rst @@ -97,7 +97,7 @@ home\_page.html). Edit {% block body_class %}template-homepage{% endblock %} {% block content %} - {{ self.body|richtext }} + {{ page.body|richtext }} {% endblock %} .. figure:: ../_static/images/tutorial/tutorial_3.png @@ -118,7 +118,7 @@ of a ``RichTextField``: .. code-block:: html+django {% load wagtailcore_tags %} - {{ self.body|richtext }} + {{ page.body|richtext }} Produces: @@ -182,12 +182,12 @@ Create a template at ``blog/templates/blog/blog_page.html``: {% block body_class %}template-blogpage{% endblock %} {% block content %} -

{{ self.title }}

-

{{ self.date }}

+

{{ page.title }}

+

{{ page.date }}

-
{{ self.intro }}
+
{{ page.intro }}
- {{ self.body|richtext }} + {{ page.body|richtext }} {% endblock %} Run ``python manage.py makemigrations`` and ``python manage.py migrate``. @@ -252,16 +252,16 @@ Adjust your blog page template to include the image: {% block body_class %}template-blogpage{% endblock %} {% block content %} -

{{ self.title }}

-

{{ self.date }}

+

{{ page.title }}

+

{{ page.date }}

- {% if self.main_image %} - {% image self.main_image width-400 %} + {% if page.main_image %} + {% image page.main_image width-400 %} {% endif %} -
{{ self.intro }}
+
{{ page.intro }}
- {{ self.body|richtext }} + {{ page.body|richtext }} {% endblock %} .. figure:: ../_static/images/tutorial/tutorial_6.png @@ -297,9 +297,9 @@ The above creates an index type to collect all our blog posts. {% block body_class %}template-blogindexpage{% endblock %} {% block content %} -

{{ self.title }}

+

{{ page.title }}

-
{{ self.intro|richtext }}
+
{{ page.intro|richtext }}
{% endblock %} Related items @@ -390,13 +390,13 @@ Extend ``blog_index_page.html`` to show related items {% block body_class %}template-blogindexpage{% endblock %} {% block content %} -

{{ self.title }}

+

{{ page.title }}

-
{{ self.intro|richtext }}
+
{{ page.intro|richtext }}
- {% if self.related_links.all %} + {% if page.related_links.all %} diff --git a/docs/reference/contrib/forms.rst b/docs/reference/contrib/forms.rst index 7fe0076f54..2e893e1e4b 100644 --- a/docs/reference/contrib/forms.rst +++ b/docs/reference/contrib/forms.rst @@ -53,19 +53,19 @@ Within the ``models.py`` of one of your apps, create a model that extends ``wagt If you do not want your form page type to offer form-to-email functionality, you can inherit from AbstractForm instead of ``AbstractEmailForm``, and omit the ``to_address``, ``from_address`` and ``subject`` fields from the ``content_panels`` definition. -You now need to create two templates named ``form_page.html`` and ``form_page_landing.html`` (where ``form_page`` is the underscore-formatted version of the class name). ``form_page.html`` differs from a standard Wagtail template in that it is passed a variable ``form``, containing a Django ``Form`` object, in addition to the usual ``self`` variable. A very basic template for the form would thus be: +You now need to create two templates named ``form_page.html`` and ``form_page_landing.html`` (where ``form_page`` is the underscore-formatted version of the class name). ``form_page.html`` differs from a standard Wagtail template in that it is passed a variable ``form``, containing a Django ``Form`` object, in addition to the usual ``page`` variable. A very basic template for the form would thus be: .. code-block:: html {% load wagtailcore_tags %} - {{ self.title }} + {{ page.title }} -

{{ self.title }}

- {{ self.intro|richtext }} -
+

{{ page.title }}

+ {{ page.intro|richtext }} + {% csrf_token %} {{ form.as_p }} diff --git a/docs/reference/contrib/routablepage.rst b/docs/reference/contrib/routablepage.rst index 5fd030a75e..db8c0d1083 100644 --- a/docs/reference/contrib/routablepage.rst +++ b/docs/reference/contrib/routablepage.rst @@ -137,6 +137,6 @@ The ``routablepageurl`` template tag {% load wagtailroutablepage_tags %} - {% routablepageurl self "feed" %} - {% routablepageurl self "archive" 2014 08 14 %} - {% routablepageurl self "food" foo="bar" baz="quux" %} + {% routablepageurl page "feed" %} + {% routablepageurl page "archive" 2014 08 14 %} + {% routablepageurl page "food" foo="bar" baz="quux" %} diff --git a/docs/reference/contrib/staticsitegen.rst b/docs/reference/contrib/staticsitegen.rst index e4d9a8e4ff..3d2853f0cc 100644 --- a/docs/reference/contrib/staticsitegen.rst +++ b/docs/reference/contrib/staticsitegen.rst @@ -76,11 +76,11 @@ Then in the template, you can use the ``{% routablepageurl %}`` tag to link betw {% load wagtailroutablepage_tags %} {% if results.has_previous %} - Next page + Next page {% else %} {% if results.has_next %} - Next page + Next page {% else %} diff --git a/docs/reference/pages/model_recipes.rst b/docs/reference/pages/model_recipes.rst index c0a8864d83..7b25524b51 100644 --- a/docs/reference/pages/model_recipes.rst +++ b/docs/reference/pages/model_recipes.rst @@ -7,7 +7,7 @@ Recipes Overriding the :meth:`~wagtail.wagtailcore.models.Page.serve` Method -------------------------------------------------------------------- -Wagtail defaults to serving :class:`~wagtail.wagtailcore.models.Page`-derived models by passing ``self`` to a Django HTML template matching the model's name, but suppose you wanted to serve something other than HTML? You can override the :meth:`~wagtail.wagtailcore.models.Page.serve` method provided by the :class:`~wagtail.wagtailcore.models.Page` class and handle the Django request and response more directly. +Wagtail defaults to serving :class:`~wagtail.wagtailcore.models.Page`-derived models by passing a reference to the page object to a Django HTML template matching the model's name, but suppose you wanted to serve something other than HTML? You can override the :meth:`~wagtail.wagtailcore.models.Page.serve` method provided by the :class:`~wagtail.wagtailcore.models.Page` class and handle the Django request and response more directly. Consider this example from the Wagtail demo site's ``models.py``, which serves an ``EventPage`` object as an iCal file if the ``format`` variable is set in the request: @@ -113,7 +113,7 @@ First, ``models.py``: def serve(self, path_components=[]): return render(request, self.template, { - 'self': self, + 'page': page, 'echo': ' '.join(path_components), }) @@ -187,7 +187,7 @@ Now that we have the many-to-many tag relationship in place, we can fit in a way blogs = blogs.filter(tags__name=tag) return render(request, self.template, { - 'self': self, + 'page': page, 'blogs': blogs, }) @@ -195,10 +195,10 @@ Here, ``blogs.filter(tags__name=tag)`` invokes a reverse Django queryset filter .. code-block:: html+django - {% for tag in self.tags.all %} - {{ tag }} + {% for tag in page.tags.all %} + {{ tag }} {% endfor %} -Iterating through ``self.tags.all`` will display each tag associated with ``self``, while the link(s) back to the index make use of the filter option added to the ``BlogIndexPage`` model. A Django query could also use the ``tagged_items`` related name field to get ``BlogPage`` objects associated with a tag. +Iterating through ``page.tags.all`` will display each tag associated with ``page``, while the link(s) back to the index make use of the filter option added to the ``BlogIndexPage`` model. A Django query could also use the ``tagged_items`` related name field to get ``BlogPage`` objects associated with a tag. This is just one possible way of creating a taxonomy for Wagtail objects. With all of the components for a taxonomy available through Wagtail, you should be able to fulfill even the most exotic taxonomic schemes. diff --git a/docs/topics/images/using_in_templates.rst b/docs/topics/images/using_in_templates.rst index 4a5251db46..ae3c97c7bf 100644 --- a/docs/topics/images/using_in_templates.rst +++ b/docs/topics/images/using_in_templates.rst @@ -16,12 +16,12 @@ For example: {% load wagtailimages_tags %} ... - {% image self.photo width-400 %} + {% image page.photo width-400 %} - {% image self.photo fill-80x80 %} + {% image page.photo fill-80x80 %} -In the above syntax example ``[image]`` is the Django object refering to the image. If your page model defined a field called "photo" then ``[image]`` would probably be ``self.photo``. The ``[resize-rule]`` defines how the image is to be resized when inserted into the page; various resizing methods are supported, to cater for different usage cases (e.g. lead images that span the whole width of the page, or thumbnails to be cropped to a fixed size). +In the above syntax example ``[image]`` is the Django object refering to the image. If your page model defined a field called "photo" then ``[image]`` would probably be ``page.photo``. The ``[resize-rule]`` defines how the image is to be resized when inserted into the page; various resizing methods are supported, to cater for different usage cases (e.g. lead images that span the whole width of the page, or thumbnails to be cropped to a fixed size). Note that a space separates ``[image]`` and ``[resize-rule]``, but the resize rule must not contain spaces. @@ -36,7 +36,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo max-1000x500 %} + {% image page.photo max-1000x500 %} Fit **within** the given dimensions. @@ -47,7 +47,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo min-500x200 %} + {% image page.photo min-500x200 %} **Cover** the given dimensions. @@ -58,7 +58,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo width-640 %} + {% image page.photo width-640 %} Reduces the width of the image to the dimension specified. @@ -67,7 +67,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo height-480 %} + {% image page.photo height-480 %} Resize the height of the image to the dimension specified.. @@ -76,7 +76,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo fill-200x200 %} + {% image page.photo fill-200x200 %} Resize and **crop** to fill the **exact** dimensions. @@ -98,7 +98,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo fill-200x200-c100 %} + {% image page.photo fill-200x200-c100 %} This will crop the image as much as it can, but will never crop into the focal point. @@ -109,7 +109,7 @@ The available resizing methods are: .. code-block:: html+django - {% image self.photo original %} + {% image page.photo original %} Leaves the image at its original size - no resizing is performed. @@ -132,7 +132,7 @@ Extra attributes can be specified with the syntax ``attribute="value"``: .. code-block:: html+django - {% image self.photo width-400 class="foo" id="bar" %} + {% image page.photo width-400 class="foo" id="bar" %} No validation is performed on attributes added in this way so it's possible to add `src`, `width`, `height` and `alt` of your own that might conflict with those generated by the tag itself. @@ -143,17 +143,17 @@ Wagtail can assign the image data to another variable using Django's ``as`` synt .. code-block:: html+django - {% image self.photo width-400 as tmp_photo %} + {% image page.photo width-400 as tmp_photo %} {{ self.photo.title }} + height="{{ tmp_photo.height }}" alt="{{ page.photo.title }}" class="my-custom-class" /> This syntax exposes the underlying image "Rendition" (``tmp_photo``) to the developer. A "Rendition" contains just the information specific to the way you've requested to format the image i.e dimensions and source URL. If your site defines a custom image model using ``AbstractImage``, then any additional fields you add to an image e.g a copyright holder, are **not** part of the image *rendition*, they're part of the image *model*. -Therefore in the above example, if you'd added the field ``foo`` to your AbstractImage you'd access it using ``{{ self.photo.foo }}`` not ``{{ tmp_photo.foo }}``. +Therefore in the above example, if you'd added the field ``foo`` to your AbstractImage you'd access it using ``{{ page.photo.foo }}`` not ``{{ tmp_photo.foo }}``. (Due to the links in the database between renditions and their parent image, you could also access it as ``{{ tmp_photo.image.foo }}`` but this is clearly confusing.) diff --git a/docs/topics/pages.rst b/docs/topics/pages.rst index 84bc1742e9..a342ada2b4 100644 --- a/docs/topics/pages.rst +++ b/docs/topics/pages.rst @@ -212,7 +212,7 @@ You just need to create a template in a location where it can be accessed with t Template context ---------------- -Wagtail renders templates with the ``self`` variable bound to the page instance being rendered. Use this to access the content of the page. For example, to get the title of the current page, do ``{{ self.title }}``. All variables provided by `context processors `_ are also available. +Wagtail renders templates with the ``page`` variable bound to the page instance being rendered. Use this to access the content of the page. For example, to get the title of the current page, do ``{{ page.title }}``. All variables provided by `context processors `_ are also available. Customising template context @@ -239,7 +239,7 @@ The variables can then be used in the template: .. code-block:: HTML+Django - {{ self.title }} + {{ page.title }} {% for entry in blog_entries %} {{ entry.title }} diff --git a/docs/topics/snippets.rst b/docs/topics/snippets.rst index 2db8a65814..0c6c41a945 100644 --- a/docs/topics/snippets.rst +++ b/docs/topics/snippets.rst @@ -117,7 +117,7 @@ In the above example, the list of adverts is a fixed list, displayed as part of ] -The snippet could then be accessed within your template as ``self.advert``. +The snippet could then be accessed within your template as ``page.advert``. To attach multiple adverts to a page, the ``SnippetChooserPanel`` can be placed on an inline child object of ``BookPage``, rather than on ``BookPage`` itself. Here this child model is named ``BookPageAdvertPlacement`` (so called because there is one such object for each time that an advert is placed on a BookPage): @@ -164,7 +164,7 @@ These child objects are now accessible through the page's ``advert_placements`` .. code-block:: html+django - {% for advert_placement in self.advert_placements.all %} + {% for advert_placement in page.advert_placements.all %}

{{ advert_placement.advert.text }}

{% endfor %} diff --git a/docs/topics/streamfield.rst b/docs/topics/streamfield.rst index 7a01f26651..185f9c90fa 100644 --- a/docs/topics/streamfield.rst +++ b/docs/topics/streamfield.rst @@ -362,7 +362,7 @@ The simplest way to render the contents of a StreamField into your template is t .. code-block:: html+django - {{ self.body }} + {{ page.body }} This will render each block of the stream in turn, wrapped in a ``
`` element (where ``my_block_name`` is the block name given in the StreamField definition). If you wish to provide your own HTML markup, you can instead iterate over the field's value to access each block in turn: @@ -370,7 +370,7 @@ This will render each block of the stream in turn, wrapped in a ``
- {% image self.photo width-400 %} -

{{ self.first_name }} {{ self.surname }}

- {{ self.bound_blocks.biography.render }} + {% image value.photo width-400 %} +

{{ value.first_name }} {{ value.surname }}

+ {{ value.bound_blocks.biography.render }}
-The line ``self.bound_blocks.biography.render`` warrants further explanation. While blocks such as RichTextBlock are aware of their own rendering, the actual block *values* (as returned when accessing properties of a StructBlock, such as ``self.biography``), are just plain Python values such as strings. To access the block's proper HTML rendering, you must retrieve the 'bound block' - an object which has access to both the rendering method and the value - via the ``bound_blocks`` property. +The line ``value.bound_blocks.biography.render`` warrants further explanation. While blocks such as RichTextBlock are aware of their own rendering, the actual block *values* (as returned when accessing properties of a StructBlock, such as ``value.biography``), are just plain Python values such as strings. To access the block's proper HTML rendering, you must retrieve the 'bound block' - an object which has access to both the rendering method and the value - via the ``bound_blocks`` property. Custom block types diff --git a/docs/topics/writing_templates.rst b/docs/topics/writing_templates.rst index 404cb37b10..2848a305b3 100644 --- a/docs/topics/writing_templates.rst +++ b/docs/topics/writing_templates.rst @@ -39,7 +39,7 @@ For more information, see the Django documentation for the `application director Page content ~~~~~~~~~~~~ -The data/content entered into each page is accessed/output through Django's ``{{ double-brace }}`` notation. Each field from the model must be accessed by prefixing ``self.``. e.g the page title ``{{ self.title }}`` or another field ``{{ self.author }}``. +The data/content entered into each page is accessed/output through Django's ``{{ double-brace }}`` notation. Each field from the model must be accessed by prefixing ``page.``. e.g the page title ``{{ page.title }}`` or another field ``{{ page.author }}``. Additionally ``request.`` is available and contains Django's request object. @@ -95,10 +95,10 @@ For example: {% load wagtailimages_tags %} ... - {% image self.photo width-400 %} + {% image page.photo width-400 %} - {% image self.photo fill-80x80 %} + {% image page.photo fill-80x80 %} See :ref:`image_tag` for full documentation. @@ -117,7 +117,7 @@ Only fields using ``RichTextField`` need this applied in the template. {% load wagtailcore_tags %} ... - {{ self.body|richtext }} + {{ page.body|richtext }} Responsive Embeds ----------------- @@ -159,7 +159,7 @@ Takes a Page object and returns a relative URL (``/foo/bar/``) if within the sam {% load wagtailcore_tags %} ... - + .. _slugurl_tag: @@ -172,7 +172,7 @@ Takes any ``slug`` as defined in a page's "Promote" tab and returns the URL for {% load wagtailcore_tags %} ... - + .. _static_tag: