Is it possible to load element from collection in the way that it's templating will have access to the variables from where it got loaded, like the include have?
When it is included in following way:
{{ site.blocks | where: "tag", "test" | first }}
Then the page variable is set to the collection document instead of the page that loads it.
Related
I have a file (a resume) which changes over time, also by name (say 'resume-january-2019.pdf', 'resume-march-2019.PDF', etc.
With Jekyll and Liquid, how can I use the static_files functionality to link to this document, without ever having to change the link itself?
I find examples of looping over images, but since it is only one file, this is not what I want.
I have defined my static files in my _config.yml
defaults:
- scope:
path: "assets/files/resume"
values:
resume: true
I am looking for something like
Resume
But then the href stays empty
I have also tried
{% assign resume = site.static_files | where: "resume", true %}
<p>Please read my Resume.</p>
Here the href stays empty as well
I would expect it to be
<p>Please read my Resume.</p>
And when I replace the resume with another file with another name, it to be
<p>Please read my Resume.</p>
You should be able to do something like this by filtering the static files with a where_exp. You may need to add an additional sort filter based on the modified date value of the file, if you plan on having more than one resume file in that folder at a time. Example without the sorting:
{%- assign resume = site.static_files | where_exp: "file", "file.path contains 'files/resume'" -%}
<p>Please read my Resume.</p>
The official Jekyll docs explain all the values you can access on a static file entry here and the filters you can apply here.
Currently, I use the following code to include another HTML file:
{% include "machines/opennebula/resources.html" %}
I am adding another folder to add another version of resources.html (specifically to support OpenStack when I want to swap to using that cloud platform):
machines/openstack/resources.html
I want to have the path change based on whichever is set in a config file (which I incorporate into other parts of the file I'm working on using):
{{ cloudPlatform }}
I tried:
{% include "machines/{{ cloudPlatform }}/resources.html" %}
This worked when using it in association with the script tag however it hasn't worked with Django's include statement. My question is how do I make something equivalent (that works in HTML) with Django?
i'm kinda new to jekyll. in my project i have few .md files(each file relate to a portfolio project). some of those need to generate separate .html files when built(which jekyll already does). but i want to exclude some files from being creating separate html files.
But the important thing is, even though i want to exclude those .md files from creating seperate .html files i still want to use the front matter of those files.(as i'm using a for loop to generate a list of all the portfolio projects)
i tryied adding those .md files to the _config.yml under exclude. but that will stop parsing the front matter as well.
is there a way in jekyll which i can achieve this.
edit:
project1.md
---
title: project1
display: true
category: portfolioProjects
---
This is a test content
project2.md
---
title: project2
display: false
category: portfolioProjects
---
if i have 2 files like above, i would like to render project1.md as a .html file(as it has a content to be shown in a page) and not generate project2.md as a separate file.But i still want to access front matters of both files to make a list of projects like,
{% for project in site.projects %}
{{project.title}}
{% endfor %}
I believe i can use 2 types of collections and set output to true
for one type of collection and false to other type of collection.
But I'm wondering whether there is a much cleaner way like conditionally setting output to true or false depending on a front matter value.
eg. output : (display)? true : false
I am trying to use asset url,
{{'Archt-Quick-Start-Guide-FR.jpg' | asset_url }}
but after saving the page its converting it to this, like encoded in URI,
%7B%7B'Archt-Quick-Start-Guide-FR.jpg'%20%7C%20asset_url%7D%7D.
Please Help!
You cannot add a liquid code in the "Page" on Shopify. It will just treat it as another html object. You can instead do the following in the Shopify -> Admin Panel -> Online Store -> Themes -> Edit HTML/CSS
Click on Add a new template under Templates
Select "Create a new template for page" and give it a name.
In this newly created template, add your code and load it into a JS variable right at the start of the page. <script>var test = '{{ 'Archt-Quick-Start-Guide-FR.jpg' | asset_url }}'</script>
This will load the link of the image into test.
Next, go to the page you are editing under Shopify -> Admin Panel -> Online Store -> Pages -> Your Page
Now use JavaScript function to load the "test" variable into the element as required.
Are you using a standard page from Online Store > Pages or are you editing a theme file?
Try this:
{{ 'Archt-Quick-Start-Guide-FR.jpg' | asset_url | img_tag }}
currently I'm working on static website, so I'm using jekyll to generate it. To have a nice structure and fancy URLs, I use permalinks.
permalink: /impressum/
So for example the impressum.html is rendered to impressum/index.html. And in my HTML i can simply link to that file with
<a href="/impressum">
That works for me very well. But you know, I'm a programmer. What if I want for example to change the URL to /imprint/? Well, I can change the permalink without any problems. But what's about all the other links on the site? Yeah, sure, I can use the search & replace function of my editor to change the linked URLs and check the whole site with a site checker for broken links, but that's not the fancy way I want to go. That's why I tried to create some kind of global variables with the permalink.
_config.yml:
lnk_impressum: /impressum/
impressum.html
---
layout: layout
title: Your New Jekyll Site
permalink: {{ site.lnk_impressum }}
---
But that does not work. I get this error:
Generating... error: no implicit conversion of Hash into String. Use --trace to view backtrace
So what's wrong or is there a better way?
It doesn't seem to be possible to place Liquid tags inside the YAML Frontmatter or _config files, per this SO answer.
Something else you could try is based on the approach used by the documentation pages for Bootstrap, which uses a Page Variable they call slug that provides a unique, unchanging reference to each page.
For instance, if you'd like to place a link to your impressum.html page (for which the permalink could change), you can place this code on another page, such as index.html:
{% for mypage in site.pages %}
{% if mypage.slug == 'impressum' %}
Link to Impressum page
{% endif %}
{% endfor %}
Then, in the YAML frontmatter for each of your pages, place code similar to the following:
---
slug: impressum
permalink: /my-permalink-to-impressum/
---
To change your permalinks in the future, you would just make the change to the Page Variable permalink in each page. The URLs referenced in your other pages would be automatically updated by Jekyll, as long as the slug variable remains unchanged.