I have a new Preact project which was generated using preact-cli and the default template.
I'm using Bootstrap components from react-bootstrap.
The default template looks like this:
├── assets
├── components
│ ├── app.js
│ └── header
│ ├── index.js
│ └── style.css
├── index.js
├── manifest.json
├── routes
│ ├── home
│ │ ├── index.js
│ │ └── style.css
│ └── profile
│ ├── index.js
│ └── style.css
│ └── style.css
└── style
└── index.css
I created a new component with a Card from react-bootstrap:
<Card as="a" href="#" class={style.customCard}>
<Card.Body>
<Card.Title>Card Title</Card.Title>
<Card.Text>
Some quick example text to build on the card title.
</Card.Text>
</Card.Body>
</Card>
In the corresponding style.css in the same directory, I added this:
.customCard {
background-color: red;
border: 5px solid red;
color: red;
}
None of these styles seem to be applied. If I inspect the element in Developer Tools, you can see that the class is not applied:
<a href="#" class="card">
<div class="card-body">
<div class="card-title h5">Card Title</div>
<p class="card-text">
Some quick example text to build on the card title.
</p>
</div>
</a>
I wonder if anyone could explain why this is happening, perhaps offering a workaround.
Related
I'm trying to customise the look of the DRF tutorial API by following this - https://www.django-rest-framework.org/topics/browsable-api/?q=base.html#the-browsable-api.
If I use a web address in the api.html href here, it works:
{% extends "rest_framework/base.html" %}
{% block bootstrap_theme %}
<link rel="stylesheet" href="https://bootswatch.com/5/vapor/bootstrap.min.css" type="text/css">
{% endblock %}
If I download bootstrap.min.css, where should I put it, and what should the href path be?
Wherever I try at the moment, I get a Not Found: error in the server logs.
Here's my TEMPLATES dictionary from settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'snippets', 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
And my directory structure:
.
└── pastebin
├── db.sqlite3
├── manage.py
├── pastebin
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── pathtest.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── snippets
├── __init__.py
├── __pycache__
├── admin.py
├── apps.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_snippet_highlighted.py
│ ├── __init__.py
│ └── __pycache__
├── models.py
├── serializers.py
├── templates
│ └── rest_framework
│ └── api.html
├── tests.py
├── urls.py
└── views.py
Thank you
I appear to have found a way. I'd be interested to know if this is the correct way.
I added a static directory with the downloaded css file in it:
.
└── pastebin
├── db.sqlite3
├── manage.py
├── pastebin
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── pathtest.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── snippets
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_snippet_highlighted.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── models.py
│ ├── serializers.py
│ ├── templates
│ │ └── rest_framework
│ │ └── api.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── static
└── bootstrap.css
I updated the settings.py file with this:
STATICFILES_DIRS = [
BASE_DIR / "static",
]
And the href in api.html like so:
{% extends "rest_framework/base.html" %}
{% block bootstrap_theme %}
<link rel="stylesheet" href="/static/bootstrap.css" type="text/css">
{% endblock %}
According to the docs here, when running the development server with python3 manage.py runserver the serving of this static file is being handled automatically.
My view folders is like
views/
└── web/
├── Frontend
│ ├── layout
│ ├── admin
│ ├── profile
│
└── Backend
├── layout
├── user
├── post
I need to make it like this:
views/
└── web/
├── Frontend
│ ├── layout
│ ├── admin
│ ├── components
│
└── Backend
├── layout
├── user
├── components
each section has his owncomponents
Is there any way to achieve to this point ?
As you would do for views, you can use the dot notation to specify the path, and so if you have a component called item.blade.php inside views/web/Frontend/components you can use
#component('web.Frontend.components.item', [...])
...
#endcomponent
Then in order to bind variables from the view to the component, you just need to pass them in the array.
Example, in your view you have a $var1 which in the component has $var2 as name, you just need to pass it like this:
#component('web.Frontend.components.item', ['var1'=>$var2])
...
#endcomponent
I'm experimenting with Spring Boot and I'm trying to create a simple custom Tag that acts as a wrapper for my JSPs. Although I have problems to load static resources from that Tag.
Below is my directory structure:
.
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com....
│ │ ├── resources
│ │ │ ├── application.properties
│ │ │ ├── static
│ │ │ | ├── js
│ │ │ | ├── css
│ │ │ | └── libraries
│ │ │ | ├── jquery
│ │ │ | └── jquery.min.js
│ │ │ | ├── bootstrap
│ │ │ | ├── ...
│ │ └── webapp
│ │ └── WEB-INF
│ │ ├── tags
│ │ └── main.tag
│ │ ├── tlds
│ │ ├── views
│ │ └── productDetails.jsp
│ └── test
│ └── java
│ └── com
Whenever a page loads, the content is fine because I can check the HTML of the page but the static resources fail to load giving me console errors:
jquery.min.js:1 Failed to load resource: the server responded with a status of 404 ()
localhost/:1 Refused to apply style from 'http://localhost:8080/product/libraries/bootstrap/bootstrap.min.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
jquery.min.js:1 Failed to load resource: the server responded with a status of 404 ()
localhost/:1 Refused to apply style from 'http://localhost:8080/product/libraries/bootstrap/bootstrap.min.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
An interesting thing is that when I change the resources with CDN links it works fine. Somehow this is with Spring but I can't figure out what.
The main.tag is as follows:
<%# tag description="Core Page Template" %>
<%# attribute name="header" fragment="true" required="false" %>
<%# attribute name="jsImports" fragment="true" required="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="libraries/bootstrap/bootstrap.min.css">
<!-- I've even tried all possible combinations of that link
(e.g /libraries or /static/libraries or I moved the whole directory
under /webapp or /webapp/WEB-INF/)
but nothing seem to work. All the time I get 404 responses from the
server -->
<jsp:invoke fragment="header"/>
</head>
<body>
<jsp:doBody/>
<script src="libraries/jquery/jquery.min.js"></script>
</body>
</html>
Which I can use from a JSP like:
<%# page contentType="text/html;charset=UTF-8" %>
<%# taglib prefix="tt" tagdir="/WEB-INF/tags" %>
<tt:main>
<jsp:attribute name="header">
<title>Products - List</title>
</jsp:attribute>
<jsp:body>
Do body....
</jsp:body>
</tt:main>
I'm encountering an issue with Pagination as I make a website; it would appear to be a nil variable, according to the command c 'paginator' when using this plugin: https://github.com/octopress/debugger
In addition, if I replace "site.posts" with "paginator.posts" in blog/index.html, I get no posts. I am running on Ruby 2.4 and Jekyll 3.3.1.
My setup is as follows:
_config.yml
gems:
- jekyll-autoprefixer
- jekyll-paginate
plugins_dir: [jekyll-autoprefixer, jekyll-paginate]
paginate: 3
paginate_path: "/blog/page:num/"
include: [ "_pages", "_posts" ]
_pages/blog/index.html
---
layout: page
title: Blog
subtitle: Blog posts
permalink: blog/index.html
---
{% for post in site.posts %}
<h1 class="post-title"> {{post.title}} </h1>
{% endfor %}
{% debug %}
<h1 class="post-title"> {{ paginator.total_posts }} </h1>
Directory Structure
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── _config.yml
├── _data
│ ├── team.yml
│ └── template.yml
├── _includes
│ ├── about.html
│ ├── clients.html
│ ├── contact.html
│ ├── css
│ │ ├── agency.css
│ │ └── bootstrap.min.css
│ ├── footer.html
│ ├── head.html
│ ├── header.html
│ ├── js.html
│ ├── modals.html
│ ├── nav.html
│ ├── portfolio_grid.html
│ ├── services.html
│ └── team.html
├── _layouts
│ ├── default.html
│ ├── feed.xml
│ ├── page.html
│ ├── style.css
│ └── team.html
├── _pages
│ ├── architecture.md
│ ├── blog
│ │ └── index.html
│ └── team.html
├── _plugins
│ └── hex_to_rgb.rb
├── _posts
│ └── 2017-05-24-test.md
├── css
├── feed.xml
├── index.html
├── js
└── style.css
(Most files removed for brevity)
Thank you for any help!
I developped a spring-boot application using thymeleaf as template. I use server context-path in my application.properties.
server.context-path: /myapp/v1.0
When I need to display images in my views.html I use this syntax
<img th:src="#{/img/first.png}" />
Everything is cool
But when I need to use images in my css file it dosn't work
/* Search input */
input.search-input {
text-align: left;
background-image: url('/img/search.png');
}
Woukd you have any idea ?
Thanks for your answers
In CSS file you should reference images using relative paths.
If your folder structure looks like (starting in src/main/resources):
.
├── application.properties
├── static
│ ├── css
│ │ └── style.css
│ └── img
│ └── first.png
└── templates
└── index.html
you should reference image in a way:
background-image: url("../img/first.png");