Skip to content

Include macros from an external file, without explicit import #243

Answered by fralau
hellt asked this question in Q&A
Discussion options

You must be logged in to vote

This is correct, and more idiomatic than your first solution. Indeed, in that way the macro will be available for all pages.

Using a Jinja2 template certainly works, and I understand why you did it.

I prefer to use f-strings for that, even though in that case it might be a little more tricky:

def define_env(env):
    """
    Macros used in SR Linux documentation
    """

    @env.macro
    def diagram(url, page, title, zoom=2):
        """
        Diagram macro
        """

        diagram_tmpl = f"""
<figure>
    <div class='mxgraph'
            style='max-width:100%;border:1px solid transparent;margin:0 auto; display:block;box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);border-radius: 0…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fralau
Comment options

Answer selected by hellt
@hellt
Comment options

@fralau
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
useful tip A how-to, good to know
2 participants