I'm using Octopress 2.0 and can't seem to get parameters to work when I set an include.
I'm basically trying to do:
{% include foo.html bar="Hello World" %}
When I load the page I get this error: Include file ‘foo.html bar="Hello World"' contains invalid characters or sequences
According to Jekyll documentation, this should work, right?
The include directive is ok and produces no error.
{% include foo.html bar="Hello World" %}
Look for an error into _includes/foo.html or send code for further investigation.
Related
I'm using webpack to build html templates using Django's templating language. Django templates contain variables and tags using {{ }} and {% %} syntax. Webpack has ignored these just fine and built the html templates as expected, except when parsing srcset tags.
Webpack errors when it tries to parse the following html:
<source srcset="{% static 'images/my-image.png' %}">
I'd like webpack to either ignore all srcset tags completely, or have some sort of # noqa equivalent which makes webpack simply not make changes to this row of the file.
Is that possible?
I don't believe this is the best solution, but one workaround which feels very hacky, is to create a global template variable that returns an empty string.
The template tag can be inserted between src and set so that webpack doesn't parse it as a srcset tag. Then when django renders the template, it replaces the template variable with an empty string (nothing).
# context processor
def dummy(request):
return {"pass": ""}
# add the context processor to your templates in settings.py
TEMPLATES[0]["OPTIONS"]["CONTEXT_PROCESSORS"].append(<path/to/dummy-context-processpr>)
src{{pass}}set="{% static 'images/my-image.webp' %} 480w, {% static 'images/my-image-800.webp' %} 800w"
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 am trying to build a dependency graph from a render of a template and I am running into a bit of trouble trying to get good information out of jinja.
I want to be able to render a template and get back a list/set of all of the files that were used to render the template. For example:
# template.html
{% extend base.html %}
{% for partial in partials %}
{% include partial %}
{% endfor %}
And have it render and find out what files were used.
# deps.py
base_path = os.path.dirname(os.path.realpath(__file__))
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(base_path))
template = jinja_env.get_template('template.html')
template.render({
"partials": [
"test1.html",
"test2.html",
],
})
# ???
looking_for = ['base.html', 'test1.html', 'test2.html']
I have checked out the AST tree and meta.find_referenced_templates(ast) but it only works when using a constant string for the include path.
Tried a custom extension looking at the tokens, but that has the same issues where I can see the variable name, but cannot get the values of the variable since it is done during the parsing/compiling phase.
Also tried overriding the {% include %} but wasn't sure how to do this correctly.
By using a custom loader I could get the values, but only if they have not been loaded before since the environment caches the loaded templates. (This solution may work if I disable the caching but then it has significant performance impact on rendering.)
How can I keep track of all the extend/include dependencies that are used for a single template render?
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.
I would like to make a categories page.
{% for post in site.categories[CATEGORY_NAME] %}
<li>{{ post.title }} ({{post.date|date:"%-d %B %Y"}})</li>
{% endfor %}
Is it possible to use a page parameter to fill in CATEGORY_NAME? Then I could have one file category.html which could serve as the index page for multiple categories (i.e. category.html?name=food and category.html?name=animals.
I've found a few plugins that handle this, but it seems like overkill to require a plugin.
https://github.com/zroger/jekyll-categories
http://blog.nitrous.io/2013/08/30/using-jekyll-plugins-on-github-pages.html
Here's the most related forum post I could find.
https://groups.google.com/forum/#!topic/jekyll-rb/y-dq-63Uvy4
If I can't do this without a plug in, is there a good reason?
I think the correct answer is that Jekyll pages must be compiled to html before they are served. This is not possible if the liquid language takes a parameter.