-
Notifications
You must be signed in to change notification settings - Fork 2
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
Global include #12
Comments
Hey @xhn35rq , thank you for your detailed help! The solution you proposed works (I didn't know that we could pass variables from the included Still, it would be nice to have some dynamically allocated global variables to be defined somewhere and to be used where needed. I would like to create a pull request from your code, can I ? |
Another small improvement: if you
You can use the variables defined in |
PR sent, select which commits you want. And it's indeed useful that includes can include other includes and pass variables between them. Include chaining...
Good point. I forgot to mention this yesterday to include directly into post or page templates, good to see you're thinking along the same lines! |
Fixed in #13 , thank you!
I agree, this is definitely a big plus. |
continuing from jekyll/jekyll#5868
I've dealt with similar things in past, and am curious if this is similar to what you're looking for. Using a variant of using includes as custom functions we can create
year_diff.html
:https://github.com/xHN35RQ/alecive.github.io/commit/0f3ad47b191b0e00cf9e87c1a3169460d3d82530
Now can call
{% include year_diff.html minus="2010" %}
anywhere in Layouts, Includes, or pages to include the above code into the layout, include or page. And output the result of the function using{{ yearDiffStr }}
:https://github.com/xHN35RQ/alecive.github.io/commit/cd1d55e2779dcf4040c89a6231fe80b7856ad8cc
You can make the include global by including it into a global include or layout such as
head.html
just like this:{% include year_diff.html minus=include.minus %}
Now we have an include (head.html) that includes a second include (year_diff.html) and each include receives the
minus
variable.Now, wherever you include
head.html
for example in default.html https://github.com/xHN35RQ/alecive.github.io/blob/master/_layouts/default.html#L4 you could change that to{% include head.html minus=page.minus %}
then just setminus: 2010
in your page front matte YAML, and use{{ yearDiffStr }}
anywhere in that page to get the return from that function.Make sense? Hope I understood your questions, and this helps. I've used this process several times before for global functions in Liquid and it's worked well for me.
The text was updated successfully, but these errors were encountered: