My post template in jekyll renders a presentation either of Google slides or of a jupyter notebook html. For this purpose, I use the markdown structure shown below:
---
layout: post
title: title
date: 2018-10-28 00:00:00 -0500
categories: category
author: author
medium: jupyter
link: [//]: # (Here I insert the presentation url)
lang: en
---
<div>
{% if page.medium == 'jupyter' %}
{% include jupyter.html link=page.link %}
{% elsif page.medium == 'gslides' %}
{% include gslides.html link=page.link %}
{% else %}
{% include nodata.html %}
{% endif %}
</div>
This generates the desired result. However, during the bundle creation, jekyll outputs this error for each post file:
Error: A Liquid tag in the excerpt of ./file.markdown couldn't be parsed.
Error: could not read file ./file.markdown: undefined method `ancestors' for nil:NilClass
I have already looked for any syntax errors along with this and other files, and all seems to be ok. Does someone has gone through a similar problem?
EDIT: I've taken the elif and the else clause of the statement, only then the problem ceases.
Related
I have a yaml file like this:
models:
- name: test_view
description: "test"
config:
meta:
database_tags:
ACCOUNT_OBJECTS.TAGS.ENV: DEV`
I am trying automatically change 'DEV' to PROD when it's in that environment. I have a macro that gets the variable from targets.name
This is the jinja code:
{% macro test_macro(target) %}
{%- if target.name == "dev" -%} DEV
{%- elif target.name == "prod" -%} PROD
{%- else -%} invalid
{%- endif -%}
{% endmacro %}`
However, when I try to use the macro I get 'test_macro is undefined'
eg. ACCOUNT_OBJECTS.TAGS.ENV: {{ test_macro(target)}}
Is it that custom macros still cannot be used in yaml files?
Macros are for templating the SQL queries DBT compiles from its models. The YAML files are for configuration; they are not themselves models and do not support macros.
I went looking, and there is an active discussion about whether this could be supported in future, but as of the end of 2022 it is not possible.
Have you considered using a config block inside your model in order to set these metadata?
I'm trying to pass one site collection to my page's layout, in order to be able to make my nav menu according to the sections I pass.
In my _config.yml
collections:
tt:
output: true
In my index.md page:
---
layout: mylayout
title: My Great Homepage
icon: fa-home
order: 1
sec: "{{site.tt}}"
---
In my layout:
---
layout: mylayout
---
{%- assign _sections = page.sec | flatify -%}
{%- include header.html scrolly_nav=_sections -%}
<!-- Main -->
<div id="main">
{{page.sec | flatify}} <!-- just to debug -->
</div>
Flatify is under _plugins/flatify.rb:
module Jekyll
module ExpandNestedVariableFilter
def flatify(input)
Liquid::Template.parse(input).render(#context)
end
end
end
Liquid::Template.register_filter(Jekyll::ExpandNestedVariableFilter)
In my layout, using {%- assign _sections = site.sec | flatify -%} works perfectly, but when I pass the collection from the page to the layout, it's not working.
If I do the exact same thing passing site.title instead of site.tt from the page to the layout, everything works just fine. But when I try to pass a collection, it's not working.
Thanks for your help.
Your flatify plugin is cool, but it does not reflect real life.
You cannot use liquid vars in front matter because they are not parsed.
In your page's front matter :
---
sec: "tt"
---
Then, from the page or the layout, you can just call :
{%- assign _sections = site[page.sec] -%}
{%- include header.html scrolly_nav=_sections -%}
If you want to debug, you can use inspect filter, which just outputs variable content.
{{ page.sec | inspect }} or {{ site[page.sec] | inspect }}
I have a an if condition in my liquid template like this
Username: {{user.email}}
{% if extras['password_to_be_sent'] %}
Password: {{extras['password_to_be_sent']}}
{% endif %}
Trial expiration: {{user.trial_expiration}}
However this is generating a line break when the if condition does not evaluate to true
so the above generated output like this
Username: Abc
Trail Expiration: 2019-11-10
I want to remove the additional line break when the if condition does not evaluate to true
i tried adding - as suggested here https://shopify.github.io/liquid/basics/whitespace/
so updated code to
Username: {{user.email}}
{%- if extras['password_to_be_sent'] -%}
Password: {{extras['password_to_be_sent']}}
{%- endif -%}
Trial expiration: {{user.trial_expiration}}
but this is giving an exception Liquid::SyntaxError (Liquid syntax error: Tag '{%- if extras['password_to_be_sent'] -%}' was not properly terminated with regexp: /\%\}/)
Additionally, I am saving the template code in database, if that helps.
Any help in this would be appreciated. Thanks.
Answered above in a comment, but here it is again:
I see you've also tagged Ruby on Rails — if your Rails app is consuming a version of Liquid earlier than 4.0.0, you won't be able to use the whitespace control tags. Those were added in Liquid 4.0.0.
Did you check to make sure extras['password_to_be_sent'] doesn't return a truthy but empty string? Maybe it should be:
Username: {{user.email}}
{%- if extras['password_to_be_sent'].present? -%}
Password: {{extras['password_to_be_sent']}}
{%- endif -%}
Trial expiration: {{user.trial_expiration}}
When I change line 134 from
int dis[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
to
int dis[4][2]={ {0,1},{0,-1},{1,0},{-1,0}};
It fixed !
I run bundle exec jekyll serve --trace on Windows 10. I got the following console message:
D:\MyPorfolio\perrot.github.io>bundle exec jekyll serve
Configuration file: D:/MyPorfolio/perrot.github.io/_config.yml
Source: D:/MyPorfolio/perrot.github.io
Destination: D:/MyPorfolio/perrot.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Liquid Exception: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in 2018-09-14-Rendering a python dict in jinja2.markdown
jekyll 3.7.3 | Error: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]
Does anyone know how to fix that problem? Thanks in advance.
The file 2018-09-14-Rendering a python dict in jinja2.markdown content is:
---
layout: post
title: "Rendering a python dict in jinja2"
date: 2018-09-14 00:01:57 +0800
categories: python jinja2
---
```python
url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'},
{'target': 'http://slash.org', 'clicks': '4'},
{'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
{'target': 'http://de.com/a', 'clicks': '0'}]
#Python 2.7
{% for key, value in url_list.iteritems() %}
<li>{{ value["target"] }}</li>
{% endfor %}
#Python 3
{% for key, value in url_list.items() %}
<li>{{ value["target"] }}</li>
{% endfor %}
```
Liquid tries to process your source code, particularly the jinja2 control tags, for that you need to tell Liquid to avoid processing it with the raw tags:
{% highlight python %}
{% raw %}
url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'},
{'target': 'http://slash.org', 'clicks': '4'},
{'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
{'target': 'http://de.com/a', 'clicks': '0'}]
#Python 2.7
{% for key, value in url_list.iteritems() %}
<li>{{ value["target"] }}</li>
{% endfor %}
#Python 3
{% for key, value in url_list.items() %}
<li>{{ value["target"] }}</li>
{% endfor %}
{% endraw %}
{% endhighlight %}
1 - The {% raw %} tag is part of the solution for you python code in this post and this post.
2 - The other part of the solution can be a bug in the way Jekyll manages excerpts.
Remove empty lines in your code, and it will work.
In my Jekyll project, I have the following in my _config.yml file:
colors:
- name: red
hex: '#FF0000'
- name: yellow
hex: '#FFFF00'
- name: blue
hex: '#0000FF'
In assets/css/colors.scss, I want to create classes for the colors as follows:
{% for color in site.colors %}
.{{ color.name }} {
color: {{ color.hex }};
}
{% endfor %}
I want to #import the colors.scss file into main.scss, but I when I do so, I get the following error:
Error in _assets/css/background-test.scss:6 Invalid CSS after "}": expected selector or at-rule, was "{% for color in..."
Liquid Exception: Invalid CSS after "}": expected selector or at-rule, was "{% for color in..." in _includes/head.html, included in _layouts/default.html
jekyll 3.0.1 | Error: Invalid CSS after "}": expected selector or at-rule, was "{% for color in..."
Is there a way to get Liquid to process the values from the _config.yml file in the SCSS partial?
Only your main.scss will be parsed by Jekyll.
Once parsed with Liquid it is passed to sass/scss processor. So, any #imported file will not be parsed by Liquid.