Python Examples of jinja2.nodes.If (2023)

The following are 30code examples of jinja2.nodes.If().You can vote up the ones you like or vote down the ones you don't like,and go to the original project or source file by following the links above each example.You may also want to check out all available functions/classes of the modulejinja2.nodes, or try the search function.

Example #1

Source File: parser.pyFrom misp42splunkwith GNU Lesser General Public License v3.0 6votesPython Examples of jinja2.nodes.If (2)Python Examples of jinja2.nodes.If (3)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #2

Source File: parser.pyFrom recruitwith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (4)Python Examples of jinja2.nodes.If (5)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #3

Source File: parser.pyFrom jboxwith MIT License 6votesPython Examples of jinja2.nodes.If (6)Python Examples of jinja2.nodes.If (7)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #4

Source File: parser.pyFrom jboxwith MIT License 6votesPython Examples of jinja2.nodes.If (8)Python Examples of jinja2.nodes.If (9)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #5

Source File: parser.pyFrom RSSNewsGAEwith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (10)Python Examples of jinja2.nodes.If (11)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #6

Source File: parser.pyFrom RSSNewsGAEwith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (12)Python Examples of jinja2.nodes.If (13)
(Video) Jinja Python - Fast Expressive Templating Engine - Advent of code Jinja2
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #7

Source File: parser.pyFrom OpenXR-SDK-Sourcewith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (14)Python Examples of jinja2.nodes.If (15)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #8

Source File: parser.pyFrom pySINDywith MIT License 6votesPython Examples of jinja2.nodes.If (16)Python Examples of jinja2.nodes.If (17)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #9

Source File: parser.pyFrom Building-Recommendation-Systems-with-Pythonwith MIT License 6votesPython Examples of jinja2.nodes.If (18)Python Examples of jinja2.nodes.If (19)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #10

Source File: parser.pyFrom scyllawith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (20)Python Examples of jinja2.nodes.If (21)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #11

Source File: parser.pyFrom cadquery-freecad-modulewith GNU Lesser General Public License v3.0 6votesPython Examples of jinja2.nodes.If (22)Python Examples of jinja2.nodes.If (23)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #12

Source File: parser.pyFrom Financial-Portfolio-Flaskwith MIT License 6votesPython Examples of jinja2.nodes.If (24)Python Examples of jinja2.nodes.If (25)
(Video) Jinja2 Templating Engine Tutorial
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #13

Source File: parser.pyFrom Financial-Portfolio-Flaskwith MIT License 6votesPython Examples of jinja2.nodes.If (26)Python Examples of jinja2.nodes.If (27)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #14

Source File: parser.pyFrom Flask-P2Pwith MIT License 6votesPython Examples of jinja2.nodes.If (28)Python Examples of jinja2.nodes.If (29)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #15

Source File: parser.pyFrom Flask-P2Pwith MIT License 6votesPython Examples of jinja2.nodes.If (30)Python Examples of jinja2.nodes.If (31)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #16

Source File: parser.pyFrom planespotterwith MIT License 6votesPython Examples of jinja2.nodes.If (32)Python Examples of jinja2.nodes.If (33)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) node.elif_ = [] node.else_ = [] token = next(self.stream) if token.test('name:elif'): node = nodes.If(lineno=self.stream.current.lineno) result.elif_.append(node) continue elif token.test('name:else'): result.else_ = self.parse_statements(('name:endif',), drop_needle=True) break return result 

Example #17

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (34)Python Examples of jinja2.nodes.If (35)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #18

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (36)Python Examples of jinja2.nodes.If (37)
(Video) Python to JavaScript - ChartJS | Jinja2
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #19

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (38)Python Examples of jinja2.nodes.If (39)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #20

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (40)Python Examples of jinja2.nodes.If (41)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #21

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (42)Python Examples of jinja2.nodes.If (43)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #22

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (44)Python Examples of jinja2.nodes.If (45)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #23

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (46)Python Examples of jinja2.nodes.If (47)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #24

Source File: parser.pyFrom luci-pywith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (48)Python Examples of jinja2.nodes.If (49)
(Video) Ansible Jinja2 Templates | #Ansible #FullCourse #Ansibleforbeginners | techbeatly
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #25

Source File: parser.pyFrom PhonePi_SampleServerwith MIT License 6votesPython Examples of jinja2.nodes.If (50)Python Examples of jinja2.nodes.If (51)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #26

Source File: parser.pyFrom PhonePi_SampleServerwith MIT License 6votesPython Examples of jinja2.nodes.If (52)Python Examples of jinja2.nodes.If (53)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. """ if name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #27

Source File: parser.pyFrom syntheticmasswith Apache License 2.0 6votesPython Examples of jinja2.nodes.If (54)Python Examples of jinja2.nodes.If (55)
def parse_if(self): """Parse an if construct.""" node = result = nodes.If(lineno=self.stream.expect('name:if').lineno) while 1: node.test = self.parse_tuple(with_condexpr=False) node.body = self.parse_statements(('name:elif', 'name:else', 'name:endif')) token = next(self.stream) if token.test('name:elif'): new_node = nodes.If(lineno=self.stream.current.lineno) node.else_ = [new_node] node = new_node continue elif token.test('name:else'): node.else_ = self.parse_statements(('name:endif',), drop_needle=True) else: node.else_ = [] break return result 

Example #28

Source File: parser.pyFrom misp42splunkwith GNU Lesser General Public License v3.0 5votesPython Examples of jinja2.nodes.If (56)Python Examples of jinja2.nodes.If (57)
def parse_statements(self, end_tokens, drop_needle=False): """Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. """ # the first token may be a colon for python compatibility self.stream.skip_if('colon') # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect('block_end') result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == 'eof': self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result 

Example #29

Source File: parser.pyFrom misp42splunkwith GNU Lesser General Public License v3.0 5votesPython Examples of jinja2.nodes.If (58)Python Examples of jinja2.nodes.If (59)
def parse_assign_target(self, with_tuple=True, name_only=False, extra_end_rules=None, with_namespace=False): """Parse an assignment target. As Jinja2 allows assignments to tuples, this function can parse all allowed assignment targets. Per default assignments to tuples are parsed, that can be disable however by setting `with_tuple` to `False`. If only assignments to names are wanted `name_only` can be set to `True`. The `extra_end_rules` parameter is forwarded to the tuple parsing function. If `with_namespace` is enabled, a namespace assignment may be parsed. """ if with_namespace and self.stream.look().type == 'dot': token = self.stream.expect('name') next(self.stream) # dot attr = self.stream.expect('name') target = nodes.NSRef(token.value, attr.value, lineno=token.lineno) elif name_only: token = self.stream.expect('name') target = nodes.Name(token.value, 'store', lineno=token.lineno) else: if with_tuple: target = self.parse_tuple(simplified=True, extra_end_rules=extra_end_rules) else: target = self.parse_primary() target.set_ctx('store') if not target.can_assign(): self.fail('can\'t assign to %r' % target.__class__. __name__.lower(), target.lineno) return target 

Example #30

Source File: parser.pyFrom misp42splunkwith GNU Lesser General Public License v3.0 5votesPython Examples of jinja2.nodes.If (60)Python Examples of jinja2.nodes.If (61)
(Video) Working with Jinja templates - Python on the web - Learning Flask Series Pt. 6
def parse_statements(self, end_tokens, drop_needle=False): """Parse multiple statements into a list until one of the end tokens is reached. This is used to parse the body of statements as it also parses template data if appropriate. The parser checks first if the current token is a colon and skips it if there is one. Then it checks for the block end and parses until if one of the `end_tokens` is reached. Per default the active token in the stream at the end of the call is the matched end token. If this is not wanted `drop_needle` can be set to `True` and the end token is removed. """ # the first token may be a colon for python compatibility self.stream.skip_if('colon') # in the future it would be possible to add whole code sections # by adding some sort of end of statement token and parsing those here. self.stream.expect('block_end') result = self.subparse(end_tokens) # we reached the end of the template too early, the subparser # does not check for this, so we do that now if self.stream.current.type == 'eof': self.fail_eof(end_tokens) if drop_needle: next(self.stream) return result 

FAQs

How to check if variable is a string in Jinja? ›

- The string test checks if a variable is a string (e.g. {% if variable is string %}Yes, the variable is a string!{% endif %} ). number (Test). - The number test returns true if a variable is a number.

How to use Jinja2 in Python? ›

Conditionals and Looping in Jinja2

Jinja in-line conditionals are started with a curly brace and a % symbol, like {% if condition %} and closed with {% endif %}. You can optionally include both {% elif %} and {% else %} tags, and for loop, we use {% for index in numbers %} and end with {% endfor %}.

What can I use instead of Jinja2 Python? ›

Jinja alternatives
  • Django Template Language (DTL) — This is the built-in templating engine for the Django web framework. ...
  • Mako — It is another templating engine for Python that emphasizes flexibility and speed. ...
  • Cheetah — It is a high-performance templating engine that is often used for large-scale web applications.

How to load Jinja template directly from filesystem? ›

The simplest way to configure Jinja to load templates for your application is to use PackageLoader . This will create a template environment with a loader that looks up templates in the templates folder inside the yourapp Python package (or next to the yourapp.py Python module).

How do you check if a string contains if condition? ›

Java String contains() method

It returns a boolean value true if the specified characters are substring of a given string and returns false otherwise. It can be directly used inside the if statement. The contains() method in Java returns true only if this string contains “s” else false.

How do you check if a certain string is in a string? ›

The includes() method

You can use JavaScript's includes() method to check whether a string contains a substring. This will return true if the substring is found, or false if not.

How to set variables in Jinja2? ›

Creating new Jinja2 variables
  1. {% set my_variable = len(todos) %} <p>You have {{ my_variable }} to-dos left.</ p>
  2. @app. ...
  3. from flask import Flask, render_template app = Flask(__name__) @app. ...
  4. from flask import Flask, render_template app = Flask(__name__) @app.

Can you use Python functions in Jinja? ›

Using a Python function in a Jinja template

These functions are placed in a dictionary. After this, the render function is created. Inside this function, we use jinja_template. globals.

How do you check if a variable is an object or string? ›

In JavaScript, we can use the typeof operator to check the type of a variable or object. The typeof operator takes a variable and returns its type in a string format. In addition, to the typeof operator, JavaScript also provides the instanceof operator to check the type of a variable or object.

How do I check if a variable is an instance of a string? ›

The is_string() function checks whether a variable is of type string or not. This function returns true (1) if the variable is of type string, otherwise it returns false/nothing.

How do you check if a variable is int or string? ›

Program to check if input is an integer or a string
  1. Take input string from user.
  2. Initialize a flag variable “isNumber” as true.
  3. For each character in the input string: a. ...
  4. If the “isNumber” flag is true, print “Integer.”
  5. If the “isNumber” flag is false, print “String.”
Apr 13, 2023

How to check string variable in JavaScript? ›

Checking the type of a variable can be done by using typeof operator. It directly applies either to a variable name or to a variable.

Videos

1. Code Generation in Python: Dismantling Jinja
(Next Day Video)
2. Python 3 Flask Jinja2 Template to Implement HTML Form Validation & Show Custom Error Messages
(Coding Shiksha)
3. DjangoCon 2021 WorkShop | Teaching cPython, Turtle Graphics, and Jinja2 | Christopher Lozinski
(DjangoCon Europe)
4. Flask 4 Control Structures in Jinja
(CSeLearning)
5. Jinja filter plugins incld. ttp
(he_pings)
6. FastAPI # 0026 # Serving Templates using Jinja2
(Sumanshu Nankana)
Top Articles
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated: 21/09/2023

Views: 6182

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.