Why Does Owl Carousel Break Bootstrap Modal In My Laravel App? - php

Good day. In my Laravel App, I have a foreach loop where I display all products. I also have a quickview modal where users can view the products without loading a new page. Furthermore, I am using owlcarousel.js to display the products. Unfortunately, owl.carousel breaks the bootstrap modal unless the modal is placed outside the owl.carousel. But, since the products are loaded on the page dynamically, I can't access the ids of the modals outside the owl carousel div which encompasses the loop.
The $modal_id variable is only returning the last Id in the loop. So, please what is the way out?
How can I access the individual ids within the loop from on click from outside
The code is shown below
<div class="product owl-carousel">
<?php $modal_id = 0; ?>
#foreach($new_arrivals as $new_arrival)
<div class="pro">
<div class="pro-img">
<?php $modal_id = $new_arrival->id?>
<span class="sticker-new">new</span>
<div class="quick-view-pro">
<a data-toggle="modal" data-target="#{{$modal_id}}" class="quick-view modal-view"
href="#{{$modal_id}}" rel="{{$new_arrival->id}}"></a>
</div>
</div>
</div>
#endforeach
</div>
<!-- Modal is shown below !-->
<div class="product-view">
<div class="container">
<div class="modal fade" id="{{$modal_id}}">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row">
</div>
</div>
<!-- Modal footer -->
</div>
</div>
</div>
</div>
</div>

Try this code:
<div class="product owl-carousel">
<?php $modal_id = 0; ?>
<?php $modal_ids = []; ?>
#foreach($new_arrivals as $new_arrival)
<div class="pro">
<div class="pro-img">
<?php $modal_id = $new_arrival->id?>
<?php $modal_ids[] = $new_arrival->id ?>
<span class="sticker-new">new</span>
<div class="quick-view-pro">
<a data-toggle="modal" data-target="#{{$modal_id}}" class="quick-view modal-view"
href="#{{$modal_id}}" rel="{{$new_arrival->id}}"></a>
</div>
</div>
</div>
#endforeach
</div>
<!-- Modal is shown below !-->
#foreach($modal_ids as $item)
<div class="product-view">
<div class="container">
<div class="modal fade" id="{{$item}}">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row">
</div>
</div>
<!-- Modal footer -->
</div>
</div>
</div>
</div>
</div>
#endforeach
Hope help you.

Related

Styling My Modal , I need My modal to have a back groundcolor of red

I need the background to be red , and the text to be white , I have tried to do it in the scss file but it just doesn't link , I used bootstrap 5
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<div class='col-12 modal-title text-center'>
<h5>Where to look for Lambdaboard</h5>
</div>
<button type="button" class="btn-close btn-plain-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-content">
<img src="<?=$base_url?>_images/animation.gif" alt="Animated Gif">
<div class="modal-footer">
<h5 class='col-12 modal-title text-center'>
A Fraction of the places you can find it
</div>
</div>
</div>
</div>
</div>
</div>
</section>
If you put a custom style class on your modal div and an other where your text is that dooesn't work ? It should

Dynamically load array of objects to view them in a modal

A PHP function loops through an array of objects and lists down their titles. I have a link that opens a modal. How can I dynamically load the modal header and body with regard to the object $r from the $results when I press details?
<?php
foreach ($results as $r) {
?>
<div class="row justify-content-center">
<div class="alert alert-success">
<strong>
<?php echo $r['_source']['title']; ?></strong> <span id="showSearchTerm"></span></br>
<a data-target="#myModal" data-toggle="modal" class="MainNavText" id="MainNavHelp" href="#myModal">Details</a>
</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<!-- <button type="button" class="close" data-dismiss="modal">×</button> -->
<h2 class="modal-title">
<?php echo $r['_source']['title']; ?>
</h2>
</div>
<div class="modal-body">
<p>
<?php echo $r['_source']['body']; ?>
</p>
<p>
<?php echo $r['_source']['path']['real']; ?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
}
Take the information you need to fill up the modal from an Ajax call. After that you can add that content with:
$(".classname").append(information_from_Ajax_call_stored_in_variable);

Unable to loop through values using for - Laravel 5.6 Blade Template

The value of the for loop is stuck at 1.
I am trying to run this loop to print the name of the event at the top of the modal box. But the same name appears each time.
I've given continue statement and tried too. Yet the value of $i is stuck at 1
It would be of great help if you could find a solution for this
Thanks in advance.
<?php $noofevents = DB::table('events')->count(); ?>
#for($i = 1; $i <= $noofevents; $i++)
<?php $current_event_name = DB::table('events')->where('id',$i)->value('Event_Name'); ?>
<div id="sponsor-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="display-4" style = "text-align : center; font-size : 30px;">Sponsors for {{$current_event_name}}</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-content">
<img src ="{{asset('images/Sponsors/paytm.jpg')}}" alt ="" width = "200px" class = "mx-auto d-block">
</div>
<div class="card-footer">
<p class = "text-center"></p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endfor
You need to differentiate modal box with different ids
Please Use this part in your controller and pass it to your blade view using compact.
<?php $noofevents = DB::table('events')->count(); ?>
Use this part in blade :
#for($i = 1; $i <= $noofevents; $i++)
<?php $current_event_name = DB::table('events')->where('id',$i)->value('Event_Name'); ?>
<div id="sponsor-modal{{ $i }}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="display-4" style = "text-align : center; font-size : 30px;">Sponsors for {{$current_event_name}}</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-content">
<img src ="{{asset('images/Sponsors/paytm.jpg')}}" alt ="" width = "200px" class = "mx-auto d-block">
</div>
<div class="card-footer">
<p class = "text-center"></p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endfor
So now you have different modal boxes for total noofevents. you need to call this modal boxes with ids appended by $i.

Dynamically pass data to a Modal from a dynamically created set of images using details from a MySQL database

I have created multiple objects using data retrieved from a MySQL database. Each object contains a clickable image and 2 headers. I can click an image which is connected to a modal but it only gives back 1 modal with the information from the very last object no matter which image is clicked.
Please help.
The following part creates the objects and works.
<div class="row kprod">
<?php
$get_kits = "select * from kitchens ORDER BY k_brand";
$run_kits = mysqli_query($con, $get_kits);
while($row_slides=mysqli_fetch_array($run_kits)){
$kit_brand = $row_slides['k_brand'];
$kit_name = $row_slides['k_name'];
$kit_img = $row_slides['k_img'];
$kit_desc = $row_slides['k_description'];
$kit_id = $row_slides['k_id'];
echo"
<div class='col-12 col-xs-12 col-md-6 col-lg-4 kpindi'>
<div class='row'>
<div class='col imgcol'>
<img class='img-fluid' src='assets/img/$kit_img' href='#portfolio-modal-1' data-toggle='modal'>
</div>
</div>
<div class='row'>
<div class='col'>
<div>
<h5 class='kprodtext' style='font-family:Adamina, serif;'>$kit_brand</h5>
<h6 class='kprodtext' style='font-family:Adamina, serif;'><em>$kit_name</em></h6>
</div>
</div>
</div>
</div>";}
?>
</div>
The next part is the modal I want to pass the data too.
<div id="portfolio-modal-1" class="modal text-center" role="dialog" tabindex="-1">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span></button>
</div>
<div class="modal-body">
<div class="container text-center">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2 class="kprodtext" style="font-family:Adamina, serif;">
Brand</h2>
<hr class="star-dark mb-5">
<img src="assets/img/image.jpg" class="img-fluid mb-5">
<h6 class="kprodtext mb-5" style="font-family:Adamina, serif;">
<i>Name</i>
</h6>
<p class="kprodtext" style="font-family:Adamina, serif;">
Desc
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
You need to assign different ids to your modals, otherwise only one will be opened.

Creating a custom Woocommerce product modal on click

I have created a basic HTML/jQuery structure for a modal that will pop up when clicked on. I'm in the process of integrating Woocommerce into my site and am unsure as to how I can do the following:
Have modal load respective product info
Integrate into a Woocommerce loop
Here is my HTML for the skeleton of what I'm trying to achieve:
<div class="col-md-4"><img src="<?php bloginfo('stylesheet_directory'); ?>/media/temp_product_images/Alto-183x300.jpg" alt="Product Img" class="product-img" data-toggle="modal" data-target="#myModal">
<p class="product-img-title text-center">Alto</p>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title text-center" id="myModalLabel">Alto</h4> </div>
<div class="modal-body" id="modal-body-one">
<div class="row">
<div class="col-sm-4"> <img src="<?php bloginfo('stylesheet_directory'); ?>/media/temp_product_images/Alto-183x300.jpg" alt="Modal Product Img" id="product-img"> </div>
<div class="col-sm-7">
<h5>Colours</h5>
<div class="scroll-container">
<div class="row">
<div class="col-xs-4">
<div class="selected-product-color"><img src="<?php bloginfo('stylesheet_directory'); ?>/media/temp_product_images/MACASSA.jpg" alt="Product Colour">
<p>Macassa</p>
</div>
</div>
</div>
<!-- End of Test Case -->
</div>
</div>
<div class="col-sm-1">
<button type="button" class="btn flip"><i class="fa fa-arrow-right" aria-hidden="true"></i></button>
</div>
</div>
</div>
<!-- Prices -->
<div class="modal-body" id="modal-body-two">
<div class="row">
<div class="col-sm-11">
<div class="row">
<h5 id="modal-prices">Download Price List</h5></div>
<div class="row">
<?php $my_query = new WP_Query('p=47');
while($my_query->have_posts()){
$my_query->the_post();
the_content();
} ?>
</div>
</div>
<div class="col-sm-1">
<button type="button" class="btn flip"><i class="fa fa-arrow-right" aria-hidden="true"></i></button>
</div>
</div>
</div>
<div class="modal-footer"> Get Quote </div>
</div>
</div>
</div>
<!-- End of Modal -->
</div>
And here is my jQuery:
//Modal Change Content
$('#modal-body-two').hide();
$('.flip').on('click', function () {
$('#modal-body-one, #modal-body-two').toggle()
});
Is there a way that I can display the product info on click within a modal using Woocommerce? Thanks

Categories