Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid considers source include as template #223

Closed
gquintana opened this issue Sep 11, 2019 · 3 comments
Closed

Liquid considers source include as template #223

gquintana opened this issue Sep 11, 2019 · 3 comments

Comments

@gquintana
Copy link

gquintana commented Sep 11, 2019

My Asciidoc file includes a YAML file

[source,yaml]
----
include::{source_dir}/group_vars/all.yml[tags=simple]
----

This YAML file contains some Jinja template markers (It's an Ansible related doc):

#tag::simple[]
admin_user_ids: |
  {{ users
  |selectattr('admin')
  |map(attribute='id')
  |join(',') }} #<1>
normal_user_count: |
  {{ users
  |rejectattr('admin')
  |list |count }} #<2>
#end::simple[]

This Jinja marker are interpreted by Liquid:

    Liquid Warning: Liquid syntax error (line 24): Unexpected character = in "{{ users |selectattr('admin') |map(attribute='id') |join(',') }}" in sources/2019-04-25-Ansible-collection-processing/group_vars/all.yml
  Liquid Exception: Liquid error (line 24): wrong number of arguments (given 1, expected 2) in sources/2019-04-25-Ansible-collection-processing/group_vars/all.yml
jekyll 3.8.6 | Error:  Liquid error (line 24): wrong number of arguments (given 1, expected 2)

When I remove the include in the Asciidoc file, the problem persists.
So I guess Liquid thinks my YAML file is for him and tries to render it.
How can I tell Liquid to skip some files?

@djencks
Copy link
Contributor

djencks commented Jan 20, 2021

I believe this would be standard Jekyll configuration of using the exclude key to exclude the yml file from processing.
https://jekyllrb.com/docs/configuration/options/

@mojavelinux
Copy link
Member

Jekyll applies liquid filtering to files that are publishable (and .adoc files if specified, see below). I see you're including a file from a publishable folder. A quick workaround is to move those files to a hidden folder, which is a folder that starts with an underscore. For example:

[source,yaml]
----
include::{source_dir}/_inc/group_vars/all.yml[tags=simple]
----

Since the file isn't published, liquid processing is guaranteed not to be applied to it.

It's important to understand that jekyll-asciidoc does not apply liquid processing to files. That's something Jekyll does all on its own. As described in the documentation, liquid processing is not enabled on .adoc files by default, so you have to explicitly enable it by setting the page-liquid attribute in the document header. See https://github.com/asciidoctor/jekyll-asciidoc#enabling-liquid-preprocessing Then Jekyll will do its thing. However, this does not extend to include files, as the linked issue explains.

@djencks this is probably worth mentioning in that section in the docs.

@djencks
Copy link
Contributor

djencks commented Jan 21, 2021

Current wording:

== Asciidoc Inclusions

The Liquid preprocessor does not process content included using the AsciiDoc include directive (see {url-issues}/166[#166]).

However, if those files are otherwise publishable, they are processed independently with the Liquid preprocessor and will appear in your site.
If this is not desired, exclude them from independent processing by one of:

* Placing them in an automatically excluded location, such as a directory starting with `_`, e.g. `_includes`.
* Naming them so as to be automatically excluded, such as starting the name with `_`, e.g. `_excluded-include.yml`.
* Configuring the link:https://jekyllrb.com/docs/configuration/options/[Jekyll excludes] so as to apply to the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants