bootstrap 4 grid row and php #foreach - php

I am trying to switch over a site to Bootstrap 4 from Bootstrap3 and having an issue with the Grid "row" option when nesting with looping through a PHP Laravel #foreach loop.
The code that I have tried in different ways looks like:
<div class="row">
<div class="col-12">
<div class="row">
#foreach($sofas as $sofa)
#if(isset($sofa['Sub']))
<a href="{{ Request::url() }}/{{ $sofa['Style'] }}">
<div class="col-12 col-sm-4 col-md-3" style="padding:0 5px 0 5px;">
<div class="product_tile">
<div class="product_tile_style">{{ $sofa['StyleName'] }}</div>
<div class="product_tile_frame">Frame {{ $sofa['Style'] }}</div>
<div class="product_tile_thumb">
<img width="200" height="140" src="/imagelib/bigthumbs/{{ $sofa['url'] }} " alt="">
</div>
</div>
</div>
</a>
#endif
#endforeach
</div>
</div>
The expected outcome should look like the following:
Example of what it should look like.
And this is the random mess that I am getting where it is shrinking everything and not expanding to the columns.
Example of what I am getting which is wrong.
Any ideas and help would be greatly appreciated.
Thank you all in advance!

Related

Display Bootstrap Featurette with a foreach

Let’s say I have a foreach post that shows the last 5 posts, and I would like to position them as the boostrap featurette (with text and image changing To left and right side: example: https://getbootstrap.com/docs/4.0/examples/carousel/
i tried but it's not display well and not responsive. so if you have time, pls help.
<div class="container">
#foreach($posts as $post)
<div class="row featurette">
<div class="col-md-7">
<h2 class="featurette-heading">{{ $post->title }}</h2>
<p class="lead">{{ $post->title }}</p>
</div>
<div class="col-md-5">
<img class="featurette-image img-fluid mx-auto" src="{{ asset('assets/img/laptop-1385702_1920.jpg') }}" alt="Generic placeholder image">
</div>
</div>
<br>
#endforeach
</div>
--> not working : result

expand / toggle div with display none from foreach with $ id

I have this:
#foreach($portfolios as $portfolio)
<div id="item-portfolio-expand{{$portfolio->id}}" class="item-portfolio-expand expand">
<div class="container">
<div class="row">
<div class="col-md-8">
col-md-8
</div>
<div class="col-md-4">
{{ __('Name')}}: {{ $portfolio->name }}
</div>
</div>
</div>
</div>
#endforeach
And this:
#foreach ($portfolios as $portfolio)
<div class="portfolio-item {{ $portfolio->tag }} " data-category="transition">
<img src="{{ $portfolio->image_show }}">
<a href="#item-portfolio-expand{{$portfolio->id}}" data-toggle="collapse" data-target="#item-portfolio-expand{{$portfolio->id}}" data-parent="#item-portfolio-expand{{$portfolio->id}}">
<div class="portfolio-item-overlay">
<p class="name-item-overlay">{{ $portfolio->name }}</p>
</div>
</a>
</div>
#endforeach
And when I press the in the first foreach, I want to toggle the second foreach at <div id = "item-portfolio-expand {{$ portfolio-> id}}" class = "item- portfolio-expand expand "> I just don't succeed at anything, I use bootstrap and jquery in the project. .item-portfolio-expand has display: none;
And at the same time when one is open and another is selected, to close the one already open and to appear the one selected with toggle.

statamic / bootstrap problem with vertical align

im newbie about statamic,
im try to solve this code :
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-sm-6 col-md-4 col-lg-3">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>
</div>
the code provide this :
i want to align these box
direzionale operativo dirigenziale not in horizonatal but in vertical like this:
direzionale
operativo
dirigenziale
i think that is a bootstrap configuration but i dont know about the statamic world
anyone can help me ?
thanks a lot
The problem here seems that you are using responsive breakpoints on your columns,
so if you want to set the boxes one below the other all the times you have to set the .col-project-box always be full-width adding this class col-12 and set the .row-project-box horizontal alignment center adding this class justify-content-center to it.
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row justify-content-center">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-12">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>

How do I loop through grid properly?

I'm currently working on a photo gallery index.
How can I make it so that my loop iterates all 4 columns and then proceeds making a new row?
This is my code:
<div class="row">
#foreach($photoGalleries as $photoGallery)
<div class="col-md-3">
<a href="{{ url('/photogalleries/' . $photoGallery->id) }}">
<img class="img-fluid" style="height: 200px; width: 200px;" src="/images/{{ $photoGallery->cover_image }}">
</a>
<h3>{{ $photoGallery->name }}</h3>
</div>
#endforeach
</div>
Now as you can imagine, it'll appear like this:
Alternative solution:
Add margin-top after the col-md-3 attribute, like so:
<div class="col-md-3" style="margin-top: 20px;">
</div>
$collectionOne = $photoGalleries->chunk(4);
#foreach($collectionOne as $collectionTwo)
<div class "row" >
#foreach($collectionTwo as $photoGallery)
<div class="col-md-3">
......
</div>
#endforeah
</div>
#endforeach

Laravel: blade foreach looping bootstrap columns

I have a foreach loop and inside that contains html with bootstrap columns.
#foreach($address as $add)
<div class="col-md-6">
Some data
</div>
#endforeach
However, bootstrap requires the row div before creating columns, placing that straight in to the foreach loop would create a row div for each col-md-6. I want to know how I can throw in the row div, skip the next loop throwing in only the closing div tag. And then repeat that process.
Example output where the loops 4 times:
<div class="row">
<div class="col-md-6">
Some data
</div>
<div class="col-md-6">
Some data
</div>
</div>
<div class="row">
<div class="col-md-6">
Some data
</div>
<div class="col-md-6">
Some data
</div>
</div>
As an alternative to Alexey Mezenin's answer you could use array_chunk instead. http://php.net/manual/en/function.array-chunk.php
#foreach(array_chunk($address, 2) as $chunk)
<div class="row">
#foreach($chunk as $add)
<div class="col-md-6">
Some data
</div>
#endforeach
</div>
#endforeach
I personally find the the above a little more readable.
Alternatively, if $address is a collection you could do $address->chunk(2) instead of array_chunk($address, 2).
If you want to change the amount of columns you have you would simply need to change the 2 to be however many columns you want.
You can use Laravel chunk in the blade template.
#foreach($products->chunk(3) as $items)
<div class="row">
#foreach($items as $item)
<div class="col-md-4 portfolio-item">
<a href="#">
<img class="img-responsive" src="{{ 'uploads/'.$item->product_image_url }}" alt="">
</a>
<h3>
{{ $item->product_name }}
</h3>
<p>{{ str_limit($item->product_description, 121) }}</p>
</div>
#endforeach
</div>
#endforeach
Copied from the blogpost.
Use the $loop variable:
<div class="row">
#foreach($address as $add)
<div class="col-md-6">
Some data
</div>
#if ($loop->iteration % 2 == 0)
</div>
<div class="row">
#endif
#endforeach
</div>

Categories