How can I create a unique overlay popup for each item in an iterated list using Django template?

Generating an iterated list of titles from context received by the template in Django is simple:

{% for instance in object_list %}
<li>{{instance.international_title}} </li>
{% endfor %}

CSS makes it easy to create a popup overlay as well:

#overlay
{
    height:300px;
    width:300px;
    margin:0 auto;
    position:relative;
    z-index:10;
    display:none;
    border:5px solid #cccccc;
    border-radius:10px;
}
<div align="center">
    <a href="#overlay"> Click Title for Detail</a>
</div>
<div id="overlay">
<p> Here is the text giving more detail<p>
</div>

The challenge arises when attempting to associate unique text with each unique title

{{instance.international_short_description}}
for the overlay popup. Is it necessary to create separate css classes like #overlay1, #overlay2 and customize href for each one? Alternatively, can a single class be used where a variable is passed to select the correct text? Unfortunately, examples demonstrating this are difficult to find.

Answer №1

To customize the id, you have the option to append the primary key of the instance. Here is an example:

{% for item in object_list %}
    <div align="center">
        <a href="#overlay<b>{{ item.pk }}</b>">{{ item.international_title }}</a>
    </div>
    <div id="overlay<b>{{ item.pk }}</b>">
    <p>{{ item.international_short_description }}<p>
    </div>
{% endfor %}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Django Email fails to properly display HTML elements

I am currently facing an issue while developing an email notification system in Django. The problem lies in the fact that the body of the email fails to render html tags properly. Instead, it displays the html tag and the message as a single long line. Eve ...

Switching between Login Form and Register Form in VueJS template

Recently, I attempted to switch between the 'Login Form' and 'Register Form' using code that I found on codepen Flat HTML5/CSS3 Login Form. While the code functioned properly on its own, when integrated into a Vue Template, the form fai ...

Switching List Icons when Hovering over Dropdown

Newbie Inquiry: I am working on a dropdown list featuring 10 items, each with black icons aligned to the right. I want to switch these icons to white when hovering over them. Appreciate any tips you may have! Thanks in advance! ...

Building a matrix of checkboxes

I am looking to design a grid of checkboxes that are displayed in columns, with 5 checkboxes in each column. <ul class="checkbox-grid"> <li><input type="checkbox" name="text1" value="value1" /><label for="text1">Text 1</lab ...

Searchbox aligned to the right using Bootstrap

Looking to place a searchbox on the right next to another container aligned left: <div> <div class="pull-left"><span>SOME TEXT</span></div> <div class="pull-right"> <div class="row"> ...

Backdrop in Bootstrap Modal Does Not Fully Cover Buttons and Input Fields

Currently, I am working with mysql and php on a user.php page that caters to user interactions. The main content in the center <div> is dynamically updated through php whenever a link on the same page is clicked. To elaborate, when a user clicks on a ...

Tips on effectively centering a wide div

After much experimentation, this is what I came up with: (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en ...

Ways to decrease the height of the navigation bar in Bootstrap version 4.1

Struggling to figure out how to decrease the height of the navbar in bootstrap v4.1. I want it to be specifically 24px tall; Thanks, Richard. ...

The voice call terminates instantly, with Nexmo disconnecting in under a second

After setting up an application in the Nexmo dashboard with event and answer URLs, I implemented the code provided by Nexmo on GitHub: client = nexmo.Client(key=api_key, secret=api_secret, application_id=application_key, private_key=private_key) response ...

Setting up the K-means PostgreSQL extension in Amazon RDS

I am currently working on a Django project that involves using geo data with GeoDjango. PostGis has been installed following the instructions provided in AWS documentation. We have a large number of markers on the map and we are looking to cluster them. ...

I am having trouble identifying the specific element in my navbar that has an unexpected margin or padding

I'm trying to get the border indicated by the arrow to extend from the top to the bottom of the navbar, but I can't seem to find where the padding or margin is that's causing it to stop short. Even after setting all padding and margin to 0p ...

Removing the restriction on maximum width to 100% and allowing for automatic height adjustment

Within my project, I have implemented a CSS technique where all images within a container are set with the attributes max-width: 100%; and height: auto;. This is done to ensure that images scale down appropriately when the viewport and container size decre ...

What is the best way to reference a div link from a different PHP file?

Struggling to access a page div from another php file, I've tried calling it using (found online) admin.php#changepass Here's an example of my HTML code: <div id="changepass" class="w3-container city" style="display:none"> <form name ...

The hyperlinks are not functioning correctly on my template

I'm using a template with the following preview link: The template includes an image of a laptop on the left side, with clickable points representing links. My goal is to make these points clickable so that they open specific pages like mbank.pl or ...

Extract value from child div using JQuery and update text in another section of the page

Here is a fiddle showcasing the concept I am working on: https://jsfiddle.net/wvz9p3e7/1/ The code is written in PHP and involves a loop for cycling through 7 or 8 different garments. My goal is to have the window on the right side of the fiddle display t ...

How can I align the logo in the center of a ul

Many have attempted to resolve this issue, creating makeshift solutions or simply settling for an outcome that just "gets by." But what is the optimal approach? I have nearly finished something, yet for some reason, the logo isn't centered, rather the ...

Ensure that the collapsing toggler and the textbox are aligned on the same line

As part of my project, I am developing a bootstrap5 website that features a search form. I am facing an issue where I am unable to align the form text box labeled "search by country" vertically on the same line as the collapsible hamburger toggler. I hav ...

How can I ensure the carousel stays centered on a webpage even after resizing the browser window?

Currently in the process of developing a website, I have implemented a jquery-based carousel on the homepage sourced from here. However, substantial modifications were made to tailor its appearance specifically for the site. The issue at hand is that I hav ...

The CSS transition fails to function correctly when rendering a React element within an array

When rendering a React component within an array using CSS transitions, I noticed that the elements in the array re-order and change style. Surprisingly, only the elements moving up have transitions applied, while the ones moving down do not. I expect all ...

Unable to modify the text color within a moving button

Working on a school project and implemented an animated button style from w3 schools. However, I'm struggling to change the text color within the button. Being new to HTML, I would greatly appreciate any insights or suggestions on what might be going ...