I have a a table with dynamic value of td, some of td will be empty and some will has value, the empty td I want there background red, and filled td should be green
I tried to do that with css by :
td:empty {
background-color: red;
}
the issue that I faced is empty td has only spaces & lines content that spaces make td:empty totally useless
in other words the css reading there is a content in td tag, but in fact that content is just spaces and lines which is fake content
how could fix his problem ?
--- update ---
here is output result : https://i.imgur.com/Qz3lE22.png
and here is the script :
<td>
{% for mission in missions|get_missions_by_user:user %}
{% if mission.start_date|date:"d-m-Y" == week_dates.6.date|date:"d-m-Y" %}
{{ mission.title }}
<!-- filled cell - this should be green background -->
<br>
{% endif %}
<!-- empty cell - this should be red background -->
{% endfor %}
</td>
Could adding the needed calss by yesno be a solution for you?
CSS:
td.empty {
background-color: red;
}
td.filled {
background-color: green;
}
HTML:
<td class='{{missions.count|yesno:"filled,empty"}}'>
{% for mission in missions %}
{% if mission == 'MISSION' %}
{{ mission }}
<!-- filled cell - this should be green background -->
<br>
{% endif %}
<!-- empty cell - this should be red background -->
{% endfor %}
</td>
Note: I've never done any code with django and I'm not familiar with python. In javascript I would check for missions.length. I think you know what I've tried above. Hope i helps.:)
Thx for every body tried to help me ,
after few days of searching and asking Javascript exports I got the script
this script is an alternative way for td:empty but trimming spaces and lines
here is the js script :
$("#tableID td:not(:first-child)").each(function () {
if ($(this).text().replace(/\s/g, "").length > 0) {
$(this).css("backgroundColor", "green");
} else {
$(this).css("backgroundColor", "red");
}
});
you have to add and remove class if tabld td is empty then add class and on that class you give background.
Related
Hello I am working on my website with multiple pages and I want to do smooth scrolling on a certain page but I don't want to use the html tag because it will only be for this specific page and not the whole website here is my code.
{% if section.settings.display_product_detail_description == false and section.settings.display_product_reviews == false and section.settings.display_shipping_returns == false %}
{% assign tab5_active = true %}
{% endif %}
<div class="scroll-to-table">
<li class = "tab-title">
<a href="#product_attributes_table" class="tab-links {% if tab5_active %} active {% endif %}">
Specs
</a>
</li>
</div>
This is the code for the HTML
div.scroll-to-table{
scroll-behavior: smooth;}
And here is the code for the CSS
At the moment all that the page is doing is a jump and not a smooth scroll. I've tried using ID instead of Class, .scroll-to-table instead of div.scroll-to-table, and changing the element in which I call the CSS from but no luck
We can add scroll-behaviour: smooth to particular page by using javascript IIFE (Immediately Invoked Function Expression). This will add the smooth behaviour to the only page that runs this script.
<script>
(function () {
document.documentElement.style.scrollBehavior = smooth;
})();
</script>
Dear stackoverflow users,
I am creating a website with flask as a backend. It will fetch some data from different systems e.x. jenkins.
one of the "data packs" will be a list of Jenkins jobs
the main .py file will include route to a page
#app.route("/simplejenkins")
def simple_jenkins():
return render_template('simplejenkins.html', job_list=job_list)
and the simplejenkins.html will iterate over the job_list and list them
{% for job in jobs_list %}
<tr>
<td>{{ job }}</td>
<td>
<p>Successful!</p>
</td>
</tr>
{% endfor %}
the idea is that the number of elements in the list will change over time.
and I want to put them in the table - each element (job) in different cell. And let's say I want to have 6 columns (depends on the screen resolution, but let's ignore this for now). So in case of 44 jobs I should have 7 full rows and 2 more job in 8th row.
and my question is, how to achieve this?
the script below generates a table with dynamic number of rows and columns but how to populate the cells using jinja?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Dynamic Table</title>
<script>
window.onload = createTable;
function createTable()
{
rn = window.prompt("Input number of rows", 1);
cn = window.prompt("Input number of columns",1);
for(var r=0;r<parseInt(rn,10);r++)
{
var x=document.getElementById('myTable').insertRow(r);
for(var c=0;c<parseInt(cn,10);c++)
{
var y= x.insertCell(c);
y.innerHTML="Row-"+r+" Column-"+c;
}
}
}
</script>
<style type="text/css">
body {margin: 30px;}
</style>
</head>
<body>
<table id="myTable" border="1">
</table><form>
</form>
</body>
</html>
i don't expect full solution of course, a link to existing similar case should be more than enough... somehow i cannot find one
thanks in advance for help
regards
Mariusz
To use that JS script all you need is an ajax call, once the page is ready, the ajax call will retrieve the data (jobs) from your flask route as JSON data and insert it in the table, with no need for jinja at all.
Or if it's not necessary for you to use a table, you can use the inline display in your frontend where your jobs will float next to each other as long as there is space, otherwise they will fall to the next line, you will loop over those jobs exactly as you did, but instead of having rows and cells you will have divs or something like that.
would you mind trying this ?
<table>
{% max_columns = 6 %}
{% interval = jobs_list|length / max_columns }
{% rows = interval|int + 1 } # +1 for the last/incomplete row
{% for p in range(rows) %}
<tr>
{% for n in range(max_columns) %}
{% cell_pos = (p * max_columns) + n }
<td>{{ jobs_list[cell_pos] }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
My case is this: I've got a Django website, and have implemented functionality to scroll through a list of photos using next- and previous arrow-buttons. This functionality works perfectly if I go to 127.0.0.1:8000, where it looks like this: 1
But on localhost:8000 this functionality does not work, and it looks like this: 2
The relevant template-code looks like this:
<div class="apartment-images">
{% for image in apartment.apartmentimage_set.all %}
<img src="{{ image.image.url }}" alt="Apartment image" class="{% if forloop.first %}active{% endif %}">
{% endfor %}
<div id="left-arrow" onclick="prevImage()"></div>
<div id="right-arrow" onclick="nextImage()"></div>
<div class="ellipses">
{% for i in apartment.apartmentimage_set.all %}<div class="ellipse {% if forloop.first %}active{% endif %}"></div>{% endfor %}
</div>
</div>
And the javascript used to show the next and the previous image:
<script>
let activeImageIndex = 0;
let apartmentImages = $('.apartment-images img');
let dots = $('.ellipse');
function nextImage() {
if (activeImageIndex < apartmentImages.length - 1) {
activeImageIndex++;
} else {
activeImageIndex = 0;
}
changeImage(activeImageIndex);
}
function prevImage() {
if (activeImageIndex > 0) {
activeImageIndex--;
} else {
activeImageIndex = apartmentImages.length - 1;
}
changeImage(activeImageIndex);
}
function changeImage(index) {
dots.removeClass('active');
dots.eq(index).addClass('active');
apartmentImages.removeClass('active');
apartmentImages.eq(index).addClass('active');
}
</script>
Now, as I've said, this functionality works on 127.0.0.1:8000 but not on localhost:8000 on the Google Chrome browser, and it works on both localhost:8000 and 127.0.0.1:8000 on Microsoft Edge browser. I've tried clearing the cookies for the localhost on Chrome.
Any help would be very much appreciated, thanks :)
I found out how to fix this!
I deleted all the buffered images and files in my chrome browser, and now it works on localhost as well :)
Here's how to do so:
https://7labs.io/tips-tricks/clear-site-specific-cookies-cache.html
I'm starting with this code:
{% for award in data.profile.awards %}
<img src="media/{{ award.Medals.ribbon }}">
{% if forloop.counter|divisibleby:3 %}
<br />
{% endif %}
{% endfor %}
my problem is that it goes from top down. Meaning that it produces the first three, then a break, then another three, and repeat from there.
What I need is to go from bottom up. in my case, If there's 4 images, I want 1 on top, and 3 on bottom. If there's 8, then there's 2 on top, 3 in the middle, then 3 on bottom. How do I do that?
Thanks.
You could possibly try to invert your loop and count from end, like this:
{% if forloop.revcounter|divisibleby:3 %}
<br>
{% endif %}
So, if for example you have 10 images, 1 images will be displayed, then condition will insert break, and break will be occurred after each 3 images.
Hope it helps!
I don't know django template language well enough, so here it is in pure js, maybe you can translate it:
var total_cells = 8;
var columns = 3;
var remainder = total_cells % columns;
for(var i=1;i<=total_cells;i++){ //starting from 1 similar to django's forloop.counter
console.log('<img>');
if((columns - remainder + i) % columns == 0){
console.log('<br>')
}
}
The idea is to calculate the remainder from total cells divided by the number of columns, which for 8 will be 2, and then insert breaks not at every 3rd position, but at every (3-remainder+1) position.
The goal is to use the variables defined in the front-matter section in a particular page.
Here my structure of the file system:
_Components
c1.html
c2.html
Here I have defined the attributes in the front-matters.
_Includes > Components
c1.html
Here I want to use a loop to refer to a variable defined in the _Components > c1.html page.
How can I achieve this goal ?
In my _Includes > Components > c1.html I have the following code:
<body class="full">
{% assign fullcomponents = site.components %}
{% for component in fullcomponents | where:"title","c1html" %}
{% component.title %}
{% endfor %}
<div class="container-fluid" id="componentscontainer">
<div class="col-md-12">
<div class="panel panel-primary" id ="panelcomponentlarge">
<div class="panel-heading" >
Chart C3 Line
</div>
etc...
Surely I'm missing some trivial things.
SECOND ATTEMPT
I figured out that I can provide a data layer for that so, I tried to split this information into a new data file.
Here the content of components.json
{
"Components": [
"ChartC3Line":{
"component":"ChartC3Line",
"description":"This is an attempt"
},
"ChartC3Lines":{
"component":"ChartC3Lines",
"description":"This is an attempt"
}
]
}
And I'm trying to get this information with the following code:
{% assign comp = site.data.components.Components[ChartC3Line] %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>
but anything is coming up.
THIRD ATTEMPT
I found a solution but I don't like it at all here my new json file
{
"ChartC3":[
{
"component":"ChartC3Line",
"description":"This is an attempt"
}],
"ChartC4":[
{
"component":"ChartC3Line",
"description":"This is an attemptSSSSSSS"
}]
}
I don't want to have an object of several arrays of one element!
Here the code to retrieve the right information:
{% assign comp = site.data.components.ChartC4[0] %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>
SOLVED
Following the structure of a json file, I changed my structure in an easier way:
{
"ChartC3":
{
"component":"ChartC3Line",
"description":"This is an attempt"
},
"ChartC4":
{
"component":"ChartC3Line",
"description":"This is an attemptSSSSSSS"
}
}
Now I can easily have access to the right object.
{% assign comp = site.data.components.ChartC3 %}
HTML:
{% highlight html linenos%}
<p> Description: {{ comp.description }} </p>