I have a blog that is based on jekyll now.But the issue I face is that the it is very difficult for me to write code here.I have already tried using <code> and ~~~ruby etc.None of them worked.This is the site for the blog.And this is the specific one I am looking at.This specifically is the repository where the blog is hosted.
No magic in Jekyll. Just Read The F.. Documentation (RTFM). See http://jekyllrb.com/docs/templates/#code-snippet-highlighting
{% highlight ruby %}
def foo
puts 'foo'
end
{% endhighlight %}
This just works.
Edit: be sure to leave a new empty line before the opening tag
<p>He had implemented ...<p>
{% highlight ruby %}
Related
I'm in the process of making a website with Django and have yet to create order_snippet.html. When I add {% include "order_snippet.html" %} I expect a TemplateDoesNotExist error, but I put this in the payment.html and commented it out like this: <!-- {% include "order_snippet.html" %} --> yet I still have a TemplateDoesNotExist error. I thought comments weren't read by html? How come this raises an error?
Django's template system knows nothing about HTML comments - it's a plain text templating system, you can use it to generate just any kind of text content. If you want to comment out part of the template code, use the template system features.
You have to comment the code with django comment template tags
https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#comment
{% comment %} {% include "order_snippet.html" %} {% endcomment %}
if you still need order_snippet.html make sure the directory is included in the settings.py
My Jekyll website has two kinds of content: personal, and professional.
I would like to emphasize which kind of content a visitor is currently reading with dynamic CSS classes:
If the visitor is on a page tagged as "personal", my <main> element's class should be "personal-content".
If the visitor is on a page tagged as "professional", my <main> element's class should be "professional-content".
Otherwise, the class should be "site-content".
In the front-matter of each page, I'm creating an output statement that I set either at "personal" or "professional", for example:
---
content: "personal"
----
Then I'm using this output statement in my tag like this: (indented for reading purposes)
<main
{% if page.content %}
class="{{ page.content }}-content"
{% else %}
class="site-content"
{% endif %}
>
However I'm only seeing styling from my site-content class. What did I do wrong?
Thanks to the comments above, I fixed it!
The problem was that I was not using a custom output statement as I thought I was: {{ content }} is already used by Jekyll to include markdown articles into HTML layouts.
So I switched {{ page.content }} to {{ page.contenttype }} and it works fine!
Caveat:
I also had to change the values I was giving my output statement. professional was working fine, but for some reason personal was returning nil. So I simply switched them for pro and perso and voilà.
I have this Liquid template which looks like this:
# /_includes/slideshow.html
{% for image in {{ include.images }} %}
...
{% endfor %}
which I'm trying to use with a YAML file (for my Jekyll site) like this:
# /index.md
{% include slideshow.html images='site.data.homepage_images' %}
The reason I see this failing is because my include variable {{ include.images }} resolves to a string within the for loop. Is there a different way to accomplish this? I'm still rather new to Liquid, YAML, Jekyll, and well, web development altogether, so any help in doing this is much appreciated!
(Note: the problem goes away if I replace {{ include.images }} with site.data.homepage_images.)
Additionally, the reason why I'm doing this (and why that crude fix isn't the solution I'm looking for) is for the ability to inject my image slideshow elsewhere around my site. It'd save a lot of code to abuse my include variable in this way.
Correct syntax in for loop is : {% for image in include.images %}
Been using Octopress for some days now. However recently met this error when using the following code block in my post:
<div class="container">
{% block content %}
{% endblock %}
</div>
The error returned is
Liquid Exception: Unknown tag 'block'
Looked around but cannot find a solution to this.
Why am I receiving a Liquid Exception?
I know this is very old, but for reference, the liquid template language in Jekyll is still rather limited. I've run across references to liquid templates with extends and block, but Jekyll doesn't support these tags.
There is no block plugin. That's the standard error you get when you are trying to use a plugin or YAML command that doesn't exist.
I think you may want one of the following:
{% blockquote %}
Four scores and sever years ago.
{% endblockquote %}
Or
{% codeblock %}
$ rake generate
$ rake deploy
{% endcodeblock %}
You should really REALLY read the documentation at Octopress. It lists everything it comes with, especially for the basics of blogging:
http://octopress.org/docs/blogging/plugins/
It has many many MANY options for just those two I posted above. For exammple, I often define the author of my blockquotes:
{% blockquote Abraham Lincoln http://www.abrahamlincolnonline.org/lincoln/speeches/gettysburg.htm The Gettysburg Address %}
Four score and seven years ago our fathers brought forth on this continent,
{% endblockquote %}
And that would show up very pretty with a nice <cite> at the bottom, with The Gettysburg Address as a link to that webpage.
I am working on a client's Django/Mezzanine website that has got some strange issue that I just can't seem to figure out. On the blog page (template of blog_post_list.html) I cannot get the meta title of the page to display, meaning
{% block meta_title %}
{{ blog_page.title }}
{% endblock %}
produces no output in the resulting html. The same holds for the meta description, but I am not worried about it as much. The strange thing is that it seems to work just fine for individual blog entries, as well as all the other pages on the website, except the blog list.
Any ideas?
Nothing is displayed in Django template if you render not existing variable or variable value is None.
First test if {{ blog_page }} renders anything. If it doesn't check if blog_page is in your template context.
You can debug template's context by writing simple custom templatetag, e.g.:
templates/your_template.html:
{% load pdb from debug %}
{% block meta_title %}
{% pdb %}
{{ blog_page.title }}
{% endblock %}
templatetags/debug.py:
from django import template
register = template.Library()
#register.simple_tag(name='pdb', takes_context=True)
def pdb(context, *args, **kwargs):
import ipdb;
ipdb.set_trace()
Apparently, there was a bit of confusion involved: I thought blog_page.title was a standard variable in mezzanine, apparently it is not, it was a custom model created by the previous developer. Since I have basically only the templates and a dump of the DB, it does not appear to be possible to restore the original model for blog_page class, so I simply solved it by supplying a meta title manually in the blog_post_list template.