I'm using AsciiDoc and Jekyll to generate a static site, based on a single HTML template. In this template, I would like to inject a variable defined in the properties of the project.
I have this part in my HTML template:
{% assign timestamp = site.time | date: '%s' %}
{% assign my_project_value = attributes.my_project_value %}
<script>
const timestamp = '{{timestamp}}';
const my_project_value = '{{my_project_value}}';
</script>
The timestamp value is correctly filled in by the HTML generator. But the my_project_value stays empty, although the variable is correctly read from the properties and known in the config used by the generator:
puts "Config: " + config.to_s
Config: {"page_ext"=>"", "title"=>"Page title",
"asciidoctor"=>{"attributes"=>{"attribute-missing"=>"warn",
..., "my_project_value"=>"SomeProjectValue", "page_ext"=>"",
"figure-caption!"=>"", "html"=>"", "title-break"=>""}}, ...}
Is there a way to modify the HTML template and inject custom values? What syntax should be used to achieve this?
I also tried using the following in the HTML page, but this also returns an empty result, so it seems as the attributes are not available at all when the template gets parsed...
<script>
const my_project_value = '{{ site.asciidoctor.attributes.my_project_value }}';
</script>
Seems my problem was caused by the fact that
site.asciidoctoris not a JSON object. With some "reparsing" in the HTML template, I could get the right value injected: