def parse(cls, parser, token): """ Parse the node syntax: .. code-block:: html+django {% page_placeholder parentobj slotname title="test" role="m" %} """ bits, as_var = parse_as_var(parser, token) tag_name, args, kwargs = parse_token_kwargs(parser, bits, allowed_kwargs=cls.allowed_kwargs, compile_args=True, compile_kwargs=True) # Play with the arguments if len(args) == 2: parent_expr = args[0] slot_expr = args[1] elif len(args) == 1: # Allow 'page' by default. Works with most CMS'es, including django-fluent-pages. parent_expr = Variable('page') slot_expr = args[0] else: raise TemplateSyntaxError("""{0} tag allows two arguments: 'parent object' 'slot name' and optionally: title=".." role="..".""".format(tag_name)) cls.validate_args(tag_name, *args, **kwargs) return cls( tag_name=tag_name, as_var=as_var, parent_expr=parent_expr, slot_expr=slot_expr, **kwargs )
def parse(cls, parser, token): """ Parse the node: {% getfirstof val1 val2 as val3 %} parser: a Parser class. token: a Token class. """ bits, var_name = parse_as_var(parser, token) tag_name, choices, _ = parse_token_kwargs(parser, bits, allowed_kwargs=()) if var_name is None: raise TemplateSyntaxError("Expected syntax: {{% {0} val1 val2 as val %}}".format(tag_name)) return cls(choices, var_name)