those.
You can use a dot (``.``) to access attributes of a variable, alternative the
-so-called "subscribe" syntax (``[]``) can be used. The following lines do
+so-called "subscript" syntax (``[]``) can be used. The following lines do
the same::
{{ foo.bar }}
configuration, the default behavior is that it evaluates to an empty string
if printed and that you can iterate over it, but every other operation fails.
-.. _notes-on-subscribing:
+.. _notes-on-subscriptions:
.. admonition:: Implementation
- The process of looking up attributes and items of objects is called
- "subscribing" an object. For convenience sake ``foo.bar`` in Jinja2
- does the following things on the Python layer:
+ For convenience sake ``foo.bar`` in Jinja2 does the following things on
+ the Python layer:
- check if there is an attribute called `bar` on `foo`.
- if there is not, check if there is an item ``'bar'`` in `foo`.
self.write(', %r)' % node.attr)
def visit_Getitem(self, node, frame):
- # slices or integer subscriptions bypass the subscribe
+ # slices or integer subscriptions bypass the getitem
# method if we can determine that at compile time.
if isinstance(node.arg, nodes.Slice) or \
(isinstance(node.arg, nodes.Const) and
"""A node that represents the from import tag. It's important to not
pass unsafe names to the name attribute. The compiler translates the
attribute lookups directly into getattr calls and does *not* use the
- subscribe callback of the interface. As exported variables may not
+ subscript callback of the interface. As exported variables may not
start with double underscores (which the parser asserts) this is not a
problem for regular Jinja code, but if this node is used in an extension
extra care must be taken.
class Getitem(Expr):
- """Subscribe an expression by an argument. This node performs a dict
- and an attribute lookup on the object whatever succeeds.
- """
+ """Get an attribute or item from an expression and prefer the item."""
fields = ('node', 'arg', 'ctx')
def as_const(self):
class Getattr(Expr):
- """Subscribe an attribute."""
+ """Get an attribute or item from an expression that is a ascii-only
+ bytestring and prefer the attribute.
+ """
fields = ('node', 'attr', 'ctx')
def as_const(self):