I am trying to extend a navbar so it appears in several pages. When I insert {% extend %} {% block content %} {% endblock %}, it only appears as text - the code dosen't work.
Here is my Navbar that I want to extend:
This is how it appears in the browser:
This is the html file I want to include my navbar in:
How it appears:
I want to inherit my navbar, but only the code text appears in the browser.
{% extend %} and so on have no special meaning in HTML.
The syntax is clearly from some template engine. Maybe Nunjucks.
You'll need to pass your source code through the template engine and use the HTML generated from it.
Related
I created a file named base.html in the templates folder and written the code as follows:
{% block page_content %}{% endblock %}
Now, in another file named Hello_World.html I wrote the code as
{% extends "base.html" %}
{% block page_content %}
<h1>Hello, World!</h1>
{% endblock %}
can anyone please explain the working of this code clearly as I didn't come across the commands block and endblock in css.To the one who answers Thank you very much in Advance!
This is Django.
block is used for overriding specific parts of a template.
You could have a block named content and this is supposed to be overridden by children that inherit from this template.
From the examples at The Django Docs
I am currently a beginner in html and I have seen this problem many times and I do not know how to solve it. I copied a source code from a video in an attempt to make a social media. The following code is in the file home.html:
{% extends 'base.html' %}
{% block title %}
home
{% endblock title %}
{% block content %}
{{hello}}
<br>
{{user}}
{% endblock content %}
{% block scripts %}
<script>
$(document).ready(function(){
console.log('working')
})
</script>
{% endblock scripts %}
However, in the video the html page seems correct and all buttons and functions are working. On the other side my html page is like this:
...
The guide you have seen concerns Flask, a framework for applications written in Python. The code will not work because there is no preprocessor that can process it. In this case the browser will show you plain text without formatting.
I'm trying to build a static website using the GRAV CMS. So far, I've been creating *.html.twig files and associating a single page to the individual template.
This is how my pages look:
{% block header%}
{% include 'partials/bhss-default-header.html.twig' %}
{% endblock %}
#CONTENT
{% block footer%}
{% include 'partials/bhss-default-footer.html.twig' %}
{% endblock %}
However, my purpose is to have an editor creating pages from the admin interface and adding HTML blocks similar to the custom fields or shortcodes in WordPress. I want this blocks to be filled with text.
I need to mention that my website is built with Semantic-UI, so I'm not using any theme provided by GRAV.
How can I replicate this behavior and what choices do I have ? The website is small at this time, so I can remake every page.
Thank you!
If you want to use editor, you need to build your header and footer as Grav pages in Markdown, not Grav theme's template file in Twig. Example:
{% block header%}
{{ pages.find('/my-header').content }}
{% endblock %}
#CONTENT
{% block footer%}
{{ pages.find('/my-footer').content }}
{% endblock %}
my-header and my-footer are 2 pages. You can unpublish these pages to hide them from your menu and forbid direct access to them.
I'm would like to use flask-admin and integrate it in my own layout which is based on flask-bootstrap. I don't care about the navbar that comes with flask-admin would just use the pure list view. I'm struggling to find an elegant solution, such that I don't have to write my own list.html. Structure is:
base.html:
{% extends "bootstrap/base.html" %}
{% block content %}
<div class="container">
{% block page_content %}
{% endblock %}
</div>
{% endblock %}
My normal other templates just extend this base.html and overwrite the page_content block. The idea is to have now my own \admin\master.html which should extend the page_content as well. Something like:
\admin\master.html
{% extends 'base.html' %}
{% block page_content %}
{% block body%} here most of the list.html from flask-admin should appear
{% endblock%}
{% endblock %}
It seems that flask-admin in list.html defines also a body block, which seems to overwrite the body block from the flask-bootstrap template. I had the impression that jijna2 templating is somehow hierarchical. e.g. blocks get filled from the direct extension.
I could easily create my own list.html, edit.html and create.html but would probably duplicate most of the code. Is there a more elegant solution?
I ended copying over everything and creating my own. I found required changes to most of those files to get things to display properly anyways.
I have a template block to override the class name in the inherited template. The resultant html from the block override is showing up the a malicious text.
Base.html:
<html>
<body>
{% block content %}
<h1 class="{% block heading_style %}Base{% endblock %}">Base Page Heading</h1>
{% endblock%}
</body>
</html>
Child.html:
{% extends "Base.html" %}
{% block content %}
{{block.super}}
{% block heading_style %}Login{% endblock %}
{% endblock %}
The block heading_style is the block I'm concerned about.
Resultant html:
As you can see the h1 class has been replaced with "Login" but it has also the started showing the "Login" as text after the h1 tag.
I'm using django 1.3.3 and eclipse with pydev. I've also checked the encoding of the html files and they and they are utf-8
You've put the definition of the heading_style block in the child within the content block. So it's being used for two things: as text content within content, and to fill the heading_style block in the parent.
Move heading_style outside of the content block definition, and it should be fine.
one endblock is missing
{% block content %}
{{block.super}}
{% block heading_style %}Login{% endblock %} {% endblock %}
I'm not sure overriding a block and nested sub-block along with {{block.super}} is good combination of doing things. May be you want to re-factor your templates for not relying on this.
Here is a ticket on django related to this (not sure this has been fixed or not) {{ block.super }} doesn't work with nested {% block %} statements