Login  Register

Re: Pass parameter from AsciiDoc CLI to HAML template

Posted by wesruv on May 21, 2020; 2:11pm
URL: https://discuss.asciidoctor.org/Pass-parameter-from-AsciiDoc-CLI-to-HAML-template-tp8023p8028.html

Thanks, that was extremely helpful!

-------
Updating my example per discussion (see the original below)

For posterity, my ascii doctor command is:
asciidoctor -T pantheon/templates/haml/html5 -a pantheonenv=localwebassets dev-assets/ascii-doc-styleguide.adoc

-a env=localwebassets being the part that sets the variable for HAML

Pantheon is the name of the project, so I'm namespacing env with that.

Then in HAML I have:
    - if (@document.attr :pantheonenv) == 'localwebassets'
      %link(rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-font/2/webfonts/red-hat-font.css")
      %link(rel="stylesheet" href="rhdocs.css")

Alternatively you can use this syntax for the condition, but I prefer the above.
    - if @document.attr? :pantheonenv, 'localwebassets'


--------
Original post:

For posterity, my ascii doctor command is:
asciidoctor -T pantheon/templates/haml/html5 -a env=localwebassets dev-assets/ascii-doc-styleguide.adoc

-a env=localwebassets being the part that sets the variable for HAML

Then in HAML I have:

    - if @document.attr? :env, 'localwebassets'
      %link(rel="stylesheet" href="https://static.redhat.com/libs/redhat/redhat-font/2/webfonts/red-hat-font.css")
      %link(rel="stylesheet" href="rhdocs.css")

Very confused why I'm using @document.attr? :env, instead of @document.attr? :env ==, BUT I confirmed the if statement evaluates properly if the var is different.

Thanks again!