flask-bootswatch: css is not loading in "/" paths - css

While working on a project which I build using Flask and a Bootswatch theme which is a books website, letting users to register, log in and then search for books and when a users selects one of results it gives information about that book,but I found out that information page which I implemented wasn't loading the styling of page, contrary to all other pages which are working fine.
My application.py for information page is:
#app.route("/book/<isbn>")
def book(isbn):
# getting the book from database
book = db.execute("SELECT * FROM books WHERE isbn=:isbn", {"isbn": isbn}).fetchone()
if book is None:
return render_template("failure.html", error="Please enter some query", code = "403!")
db.commit()
# giving details to webpage
return render_template("book.html", book = book)
as you can see I am using ISBN (International Standard Book Number), as a path for different books because each book has unique ISBN, thus I assume it is great for making links to different individual book page.
and book.html looks something like this:
<!-- further exptending the layout page -->
{% extends "layout.html" %}
<!-- further extending the title -->
{% block title %}
Books: Book Page
{% endblock %}
<!-- further extending the body -->
{% block body %}
<h3 align="center"> {{book.title}} by {{book.author}}</h3>
<div>
<li>
Title: {{book.title}}
</li>
<li>
Author: {{book.author}}
</li>
<li>
ISBN: {{book.isbn}}
</li>
<li>
Year: {{book.year}}
</li>
</div>
{% endblock %}
Please figure out where I am going wrong.

Problem is in first line here in application.py it should be
#app.route("/<isbn>")
because /book/<isbn> loads css from /book/static/bootstrap.min.css.

Related

Pelican not rendering rst title and subtitle from imported rst file

I want to import an rst file to my Pelican index page like here:
Pelican: include file's contents on main page
*****
Title
*****
subtitle
########
subsubtitle
***********
Here is some content in the document.
**ReStructuredText** (rst): plain text markup
.. image:: images/22204100065.png
:alt: exhale
:width: 512px
only from subsubtitle gets the page rendered as html.
The source of the index.html looks like this
<div class="bg-white dark:bg-zinc-800 p-4 md:p-6 mb-4 rounded-lg"><div class="section" id="subsubtitle"> <h2>subsubtitle</h2>
Here is some content in the document. ReStructuredText (rst): plain text markup
The start of the index.html template looks like this:
{% extends "base.html" %}
{% block content %}
{% block content_title %}
<div class="bg-white dark:bg-zinc-800 p-4 md:p-6 mb-4 rounded-lg">{{ INTRO }}</div>
{% if not category and not tag %}
<div class="my-12 md:my-24 text-zinc-800 dark:text-zinc-300">
{% if SOCIAL or FEED_ALL_ATOM or FEED_ALL_RSS %}
The part of my settings file looks like this (from the answer of above link):
from pelican.settings import DEFAULT_CONFIG
from pelican.readers import RstReader
config = DEFAULT_CONFIG.copy()
INTRO, _ = RstReader(config).read("content/incls/sample.rst")
I expect the Title be rendered in h1 and the Subtitle in h2.
I am using the Papyrus theme. Update: I also tried with notmyidea but have the same problem.
I tried to ask the question in a comment of the above link but I am not allowed.

Drupal 8 - reach node/content needed variables in view

New user of D8 : my problem is to access to fields in a view or even in general with Drupal 8.
As we could do with ACF in Wordpress.
a {{ kint() }} crash my chrome but works with Firefox to explore the content var.
Unfortunately I do not managed to find and use fields' variables in my view.
I create a new view, which actually display the last three articles. These are well displayed in ugly list but I want to extract fields to put them in a custom html integration.
I create and use a new template for the view :
x node--view--liste-des-actualites--page-2.html.twig
In a custom parent :
x node--page-accueil.html.twig
But when I try to kint() content in my node--view--liste-des-actualites--page-2.html.twig, I have the custom field of the page (Page accueil) and can't find the article's one.
I managed to do it in my custom page but not in this view.
{%
set classes = [
'node',
'node--type-' ~ node.bundle|clean_class,
node.isPromoted() ? 'node--promoted',
node.isSticky() ? 'node--sticky',
not node.isPublished() ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
'clearfix',
]
%}
{{ attach_library('classy/node') }}
<article{{ attributes.addClass(classes) }}>
<div{{ content_attributes.addClass('node__content', 'clearfix') }}>
{{ content }}
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<a href="{{ LINK_VAR }}" class="bloc-type">
<div class="categ categ_projet">{{ CATEGORY_VAR }}</div>
<div class="img"> <img src="{{ IMAGESRC_VAR }}" alt=""> </div>
<span class="wrapper">
<p class="date">{{ DATE_VAR }}</p>
<h3>{{ TITLE_VAR }}</h3>
</span>
</a>
</div>
</div>
</article>
EDIT
I managed to guess some fields but this is definitely not a good way to find variables..
{{ node.label }} + {{ content.field_tags }} (But I do not want a rendered one, I just want the text/value)
if you use kint(); to debug large arrays can crash your browser.
I would suggest to use the devel module https://www.drupal.org/project/devel. With devel you can debug your arrays inside of the Drupal8 UI for each content type, block or view.
In my case i use the UI of devel (additional tab on each content). in the module settings, you can chose how devel debugs, the error handling and the output.
As the OP commented it is possible to use a preprocess to display the array on your site:
function <themename>_preprocess_page(&$variables) {
dpm($variables);
}

for in twig templates of drupal is behaving strangely

I am trying to show only upcoming events from a list of events. Below is how I have tried to display.
<div class="row">
{% for item in items %}
{% if item.content['#node'].field_event_type.getValue()|first.value == 'upcoming' %}
<div class="col">{{item.content}}</div>
{% endif %}
{% endfor %}
</div>
But the output rendering is, the second event is displaying after the row div like below. I don't understand how this is happening as the for loop is inside the row div
<div class="row">
<div class="col"> content </div>
</div><div class="col"> content </div>
Expected output
<div class="row">
<div class="col"> content </div>
<div class="col"> content </div>
</div>
Twig does lots of things:
loading (open your Twig content)
parsing (create a parse tree from your Twig content)
compiling (browse that tree to create a php file)
caching (store the php file somewhere to avoid recompile it next time)
executing (execute the generated php file)
When a {% for %} is detected during parsing, Twig calls the token parser recursively until it finds {% endfor %} and builds a token tree. In your case, it would look like:
root
|
--- string
|
--- for
| |
| --- if
| |
| --- string
|
--- string
Then, Twig compiler crosses over that tree recursively and generates the corresponding php code. In that way, the following Twig loop:
{% for i in 1..5 %}
Value = {{ i }}
{% endfor %}
Compiles to this in PHP:
// line 1
$context['_parent'] = $context;
$context['_seq'] = twig_ensure_traversable(range(1, 5));
foreach ($context['_seq'] as $context["_key"] => $context["i"]) {
// line 2
echo "Value = ";
echo twig_escape_filter($this->env, $context["i"], "html", null, true);
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['_key'], $context['i'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
As you can see, a {% for %} is no more than a simple foreach and as Twig tokens are stored into a tree, it is by design not possible to display contents located below a pair of open/close tags.
The only possibility I can see is that one of the tag you're using in Twig is playing with output buffering, and one of the methods you're using in your loop breaks the ob stack (like a ob_get_clean() without any ob_start() for example, that have been open previously).
My advice is to grep your twig file name into your cache directory (eg: grep -Ri 'test.twig' cache/) in order to see that file compiled to PHP, to understand exactly what it does, and debug it.
Instead of filtering your content in twig, filter the results in your Drupal view.
In the "filter criteria" on your view, select the field_event_type field and set it "is equal to" and select/add 'upcoming' as the option.
If you filter in the view, you don't have to mess with the twig template.

How to highlight active item in custom taglist on shopify collection page

I've added custom tags to my collection pages with help from this support forum: https://ecommerce.shopify.com/c/ecommerce-design/t/change-order-in-which-tags-are-displayed-on-collection-page-179468
The tags that appear on the collection pages are defined by linklists in the navigation. There is more about this in the discussion forum I posted above.
The snippet of code I inserted into collection-template.liquid just below the header is:
{% capture collection_taglist %}{{ collection.handle | append: "-tags" }}{% endcapture %}
{% if linklists[collection_taglist] %}
<ul class="tags tags--collection inline-list">
{% for link in linklists[collection_taglist].links %}
<li>{{ link.title | link_to: link.url }}</li>
{% endfor %}
</ul>
{% endif %}
Everything is working as intended, however I cannot get the active tag to be highlighted using CSS styling. I also tried some Javascript (see below) but that does not seem to be working either.
jQuery(".tags").find("a[href='"+window .location .href+"']").each(function() {
jQuery(this).addClass("active");
});
See here: http://shopsexologyinstitute.com/collections/women (you can enter using the password 'eaclim')
Any help would be greatly appreciated!
Many thanks :)
I run into this in all sorts of circumstances. Running the following in the console outlines the issue:
jQuery(".tags").find('a').each(function(){ console.log(this.href);});
The host in the urls is not the host of the site.
You'll need to extract the pathname for comparison. There are various ways to do that but run the following in Chrome or Firefox to get the idea. URL is not widely supported so for production you'd need a different way to parse the link urls:
(function(){
var path = location.pathname;
return jQuery(".tags").find('a').filter(function(){
console.log('checking: '+ this.getAttribute('href'));
var href = new URL(this.getAttribute('href'), location.href);
console.log(href.pathname +' vs '+ path);
return href.pathname == path;
});
})();

Liquid and Jekyll - Add CSS class on occurence of character in an array

on my site i have lists using two different kinds of styles for list items. Their occurance is uneven.
For now i edit these lists manually in html. I would like to put them inside an array in the YAML front matter and let jekyll generate the appropriate lists.
Example:
My idea is to put all list items in an array in the YAML front matter and tag those, which should be italic, with a string like 'ITALIC_':
list: [ITALIC_Main, 300g tomatoes, 1 mozzarella ball, ITALIC_Dressing, olive oil, vinegar, ...]
Is it possible to check not only the array for a certain string but
the array items too?
How can i filter the tagged array items and apply a certain css class via Jekyll?
Thanks for your help!
Vin
I think you have a modeling problem ;-) You're mixing datas and style : No Goood !
I propose a more dissociated solution, with organized datas on one place and presentation in an other.
It can be something like this :
---
title: recipe
layout: default
recipe:
ingredients:
main:
- ingredient1
- ingredient2
dressing:
- ingredient3
- ingredient4
optional:
- ingredient5
operations:
.... To be continued ...
---
<h2>Ingredients</h2>
{% for part in page.recipe.ingredients %}
<h3>{{ part[0] }}</h3>
<ul>
{% for ingredient in part[1] %}
<li>{{ ingredient }}</li>
{% endfor %}
</ul>
{% endfor %}
<h2>Operations</h2>
{% for part in page.recipe.operations %}
To be continued ...
(Not tested) You can write it as: ITALIC_Main_ and in the template loop just remove the ITALIC with
{{ site.list.item | remove_first: "ITALIC" }} - this will leave you with _Main_ which is converted to italic style in markdown.

Resources