I going through various variables listed on the Templating page of sphinx. But I am not able to get the path of current html (inside the template (_template/layout.html)).
Closest I got was using rellinks. Problem is that it gives the paths of next and previous pages but not the current page.
Similarly,
{{ file }} gives ./.html
{{ pathto(pagename) }} gives ./build/html
I want the entire paths of an html file. eg. ./build/html/2017/10/12/somepage.html
How can I get it?
pagename will give you the path to the current file disregarding the file ending, relative to the root document of your Sphinx project. You don't need to wrap it into pathto().
For example, if the current document is located at /something/somepage.html in the root directory,{{ pagename }} returns something/somepage.
To retrieve the actual path, use something like:
/{{ pagename }}.html
or:
{{ '/' + pagename + '.html'}}.
Related
I am new to Jekyll and I have the following error
So I have a Jekyll project which has an index.html file,
the html file has content in yaml format in the front matter.
I would like to add an <a href=""> tag to a word, to make it clickable and work as a link but upon adding the tag I get the following error
"YAML Exception reading /Users/yapsody/Desktop/campaigns.yapsody.com/faq/index.html: (): did not find expected key while parsing a block mapping at line 38 column 5"
this is my YAML content in index.html file, the content is at the top of the page, I would like to enclose "Dashboard overview" in the anchor tag
this is how I call my yaml content:
what I would like to do is the following or something that gives me the same output (dashboard overview ) but its giving me the following error (yellow text)
Like this you can add the link:
- title: HTML
url: /html/
You can break a content and use the above way.
Please let me know if you find any issue
You can use
[your text](your link)
example
google
and after that, you are fetching this on your front end so you need to add a tag
{{faq.question | markdownify }}
Hope this will help you
for more https://www.markdownguide.org/basic-syntax/#:~:text=Don%27t%20do%20this!-,Links,-To%20create%20a
I'm creating a website using Jekyll.
so far I have four pages which are created automatically from four md files which md files are in the root of the project.
index.md
about.md
login.md
register.md
Here is the content inside my login.md file
---
layout: layout-default
title: some login title
permalink: /login
theme: secondary-theme
nav:
menu-items:
- type: text
text: Don't have an account?
- type: link
text: SIGN UP
class: button
linkPath: /register
sections:
- type: 3
class: form-section
header-line-2: Login Section!
form:
api: http://127.0.0.1:8080/login
submit-text: LOG IN
form-controls:
- label-text: EMAIL ADDRESS
input-type: email
input-placeholder: Enter your email
input-name: email
- label-text: PASSWORD
label-link-text: Forgot password?
label-link-path: #
input-type: password
input-placeholder: Enter your password
input-name: password
---
What i do is iterating the sections and applying html attribute values depending on the variables inside each section. That way i can have as many sections rendered as i want on one page. And they can also be different depending on the classes and content i put in the md file.
The problem is that if the project gets too complicated with different styles for sections and so on. I would like to separate each section content. It would be nice if i could make a folder lets say login/sections folder
and then put md files inside and then inside login.md file include these section md files. This way the code would be much more organized.
Is there way to do that, and is my approach actually good.
Jekyll provides the ability to include files into another files. The magic directory for this is _includes. Example:
If you create a file named _includes/sections/s1.html, you can include that into any other file with the following tag:
{% include sections/s1.html %}
This approach works for:
including HTML file into HTML
including HTML file into Markdown (since Markdown can contain HTML code)
including Markdown into Markdown
If you want to include a Markdown file into a HTML, you have to use some trick:
{% capture m %}{% include sections/s1.md %}{% endcapture %}
{{ m | markdownify }}
I've recently been trying to get to grips with nunjucks, I've used handlebars before so the learning curve hasn't been that bad. However there is one thing I can't seem to get working:
I've got a JSON file which has the following data in it:
"contentIntro" : {
"componentClass" : "c-global-header",
"title" : "Welcome Firstname Surname,",
"subtitle" : "New applications:",
"bodyCopy" : "You can create, edit and save the draft application as many times as you need before submitting it for assessment.",
"ctaType" : "text",
"ctaText" : "View the list",
"ctaURL" : "#"
}
This exists in a JSON file which includes other page elements but it's only the contentIntro context I'm interested in.
If I include a partial like this:
{% include "components/c-headed-text.nunjucks" %}
then I can access the JSON data using dot notation within that partial (eg {{ contentIntro.title }}), however this isn't very flexible and it precludes me having more than one of the same partial type on the page.
Ideally what I'd want to do is import the partial like this:
{% import "components/c-headed-text.nunjucks" as contentIntro %}
and then in the template I can just access the JSON data using {{ title }} as it will already know the context from the import.
Annoyingly though it doesn't work and I can't see why. The Jinja2 documentation seems to suggest it would but I can't get it to work using Nunjucks, is this even possible?
Edit: I should also add that the templates are being prerendered in gulp so the end result is just flat HTML.
Ok I've found a way around it. it's not as clean as I'd like but it does the job.
I just a normal include statement:
{% include "components/c-headed-text.nunjucks" %}
but above it a set a variable as follows:
{% set context = contentIntro %}
Then inside the partial I can just use {{ context.title }} and it works like a charm!
Ok, so let's say I use listdir to make an object of pictures, their names, sizes and their file names. The object is parsed so that each file name is item.values()[0]['item']. I am trying to do:
{% for item in banners %}
<h3>{{item.keys()[0]}} size {{item.values()[0]['size']}}:</h3>
<div>
<img src="{{url_for( 'static', filename= 'banners/{{item.values()[0]["item"]}}' )}}" />
</div>
{% endfor %}
But it is not working, replacing {{item.values()[0]["item"]}} with a specific file name is working and I can see that the file names are in the object, yet it will not generate the image, instead it says it failed to load the given url and the urls are weird, for example one shows up like:
<img src="/static/banners/%7B%7Bitem.values%28%29%5B0%5D%5B%22item%22%5D%7D%7D%7Csafe">
Something to do with it interpreting the characters as is instead of what they are to represent, but I cannot figure out the syntax. Thanks.
You are already in a {{ }} block, so nesting more of those is incorrect. I think it should be something in the lines of :
filename = 'banners/' + item.values()[0]["item"]
I have this anchor link:
{{title}}
Sometimes, this title has some content with + (add operator) like:
"Django + Python"
But when it is directly placed on anchor links, the url delivered will be:
http://127.0.0.1:8080/question/tag/1/1/?list_id=Django + Python
Which will eventually cause problem on the retrieval as the url decoder thought the list_id GET = DjangoPython.
So, does anyone knows how to avoid this issue? Note that I do not want to change anchor links to input buttons.
Instead of
{{ title }}
do
{{title|urlencode}}
Instead of hardcoding the URL and building the querystring in the template by concatenating the title context item, consider simplifying it a bit by using django.core.urlresolvers.reverse() and specifying a named URL from the relevant urls.py file. Makes for a clean design when you don't have to worry about URLs changing! Imagine the headache of all the scattered HREFs you'd have to change, versus simply assigning a context variable from the view set to the result of the reverse call. The querystring can be added nicely in the view too, without having to worry about some of the often strange template parsing rules. Note that the urllib.urlencode function acts completely differently to the template filter of the same name; don't get confused! It can be used as follows:
# If the entry in URLConf has named capture groups such as ?<pk>,
# pass a dict as kwargs parameter instead.
url = reverse('your-named-url', args=(1, 1)) # e.g '/question/tag/1/1/'
# Encodes as form data to 'list_id=Django+%2B+Python'
querystring = urllib.urlencode({'list_id': 'Django + Python'})
context['question_url'] = '{}?{}'.format(url, querystring)
Then, in the template it can be as simple as href="{{ question_url }}". It might seem like more work, but it can pay off very quickly and it's a much better separation of concerns. Normally I'd use the {% url "your-named-url" %} template tag, but it doesn't currently handle querystrings nicely -- as in, not in the same manner as it deals with URL args and kwargs defined in URLConf.