Make the globals map for a template. Any given template globals overlay the environment :attr:`globals`. Returns a :class:`collections.ChainMap`. This allows any changes to a template's globals to only affect that template, while changes to the environment's globals
(
self, d: t.Optional[t.MutableMapping[str, t.Any]]
)
| 1111 | return cls.from_code(self, self.compile(source), gs, None) |
| 1112 | |
| 1113 | def make_globals( |
| 1114 | self, d: t.Optional[t.MutableMapping[str, t.Any]] |
| 1115 | ) -> t.MutableMapping[str, t.Any]: |
| 1116 | class="st">"""Make the globals map for a template. Any given template |
| 1117 | globals overlay the environment :attr:`globals`. |
| 1118 | |
| 1119 | Returns a :class:`collections.ChainMap`. This allows any changes |
| 1120 | to a template&class="cm">#x27;s globals to only affect that template, while |
| 1121 | changes to the environment&class="cm">#x27;s globals are still reflected. |
| 1122 | However, avoid modifying any globals after a template is loaded. |
| 1123 | |
| 1124 | :param d: Dict of template-specific globals. |
| 1125 | |
| 1126 | .. versionchanged:: 3.0 |
| 1127 | Use :class:`collections.ChainMap` to always prevent mutating |
| 1128 | environment globals. |
| 1129 | class="st">""" |
| 1130 | if d is None: |
| 1131 | d = {} |
| 1132 | |
| 1133 | return ChainMap(d, self.globals) |
| 1134 | |
| 1135 | |
| 1136 | class Template: |
no outgoing calls
no test coverage detected