def get_block_with_arg(block_name, arg): block_library = BlockLibrary() block_library.autodiscover() try: return block_library.get_block(block_name)(arg) except NotInLibraryException: return ''
class BlockNode(template.Node): def __init__(self, arguments): self.block_library = BlockLibrary() self.block_library.autodiscover() self.block_name = arguments[0][1:-1] self.argument = arguments[1][1:-1] if len(arguments) > 1 else None def render(self, context): try: block = self.block_library.get_block(self.block_name) except NotInLibraryException: return '' if not self.argument: return block() else: return block(self.argument)
def __init__(self, arguments): self.block_library = BlockLibrary() self.block_library.autodiscover() self.block_name = arguments[0][1:-1] self.argument = arguments[1][1:-1] if len(arguments) > 1 else None