Search code examples
asciidoctor

Asciidoctor parametetrized template


I am using asciidoctor using asciidoctor-maven-plugin. In my document (actually documentation), I have one block repeated many times. Is there any way to do include with parameters.

What I want in pseudocode, I can't find how to write it:

template:

=== HTTP request
include::{snippets}/{variable}/http-request.adoc[]
=== HTTP response
include::{snippets}/{variable}/http-response.adoc[]

Usage

include template[variable=customer]

Thanks.


Solution

  • I think you can redefine attributes. With this tree:

    Folder
    |   main.adoc
    |   template.adoc
    |
    \---code
        +---first
        |       http-request.adoc
        |       http-response.adoc
        |
        \---second
                http-request.adoc
                http-response.adoc
    

    My main.adoc file looks like this:

    :snippets: code
    
    == First Chapter
    
    :variable: first
    
    include::template.adoc[]
    
    == Second Chapter
    
    :variable: second
    
    include::template.adoc[]
    
    == End
    
    This is the end.
    

    The previous example works, but I have the feeling that this is not exactly what you want.

    If you are looking for a Macro example, have a look at this maven & java example: java-extension-example.