Shopware Development Support
2Hats . 3 minutes

Bootstrap-like Grid System for Shopware 5 using PocketGrid

Most developers are well used to Bootstrap and it’s grid system to develop responsive websites quite fast and easy. But when they come to Shopware they are challenged with PocketGrid in the default theme, which is very light compared to Bootstrap but doesn’t really have the grid-like the workflow of Bootstrap. We believe the grid system is quite convenient so we developed something simple which helps Shopware theme developers to code easily in a style similar to Bootstrap. We still keep the lightweight PocketGrid and do not use Bootstrap libraries for they are not as light as PocketGrid. Let’s see how this is done so you can adopt this style in your agency for Shopware theme development.

How to create rows and columns using PocketGrid as it is?

Below is an illustration of how we can create rows and columns. Class block-group is for a row like a Bootstrap row and b1, b2 etc are columns inside that row.

The output will be like this:

 

So How does this grid system work?

  • b1 + b2 = 50% + 50% = 100%, so b3 goes to a new line.
  • b3 + b4 + b5 = 50% + 25% + 25% = 100%, so b6 goes to a new line.
  • b6 + b7 + b8 + b9 = 25% + 25% + 20% + 20% = 90%, but b10 has a width of 20%, so the total would be greater than 100%. Thus b10 goes to a new line!

Little messed up, right? Let’s see how we can make this easier like Bootstrap.

How can we modify PocketGrid like bootstrap column grid using a LESS mixin?

Things we noticed from the above example are:

  • each block has a block class
  • a block-group wraps all these blocks
  • blocks are stacked one below other by default with width: 100%

Things to achieve using mixin:

  • We don’t want to add class .block-group for each row every time, it’s better to have these extended with the classes we use
  • We don’t’ want to add a .block  class for each column, This also we need to apply dynamically.
  • We don’t want to use % anymore, instead, we use it like Bootstrap 12 column grid system.

Below is a mixin we created to achieve this.

Then import our mixin to less file:

In the below example let’s consider we need to build a header row with 3 columns.

Mixin overview:

  • Automatic extension of parent  (.header)  with  .block-group
  • Looping all child and extending child with .block
  • The child must be a class without a dot(.)

Eg: logo

  • We can assign grid count  with child variable after adding a space

Eg:  @child: logo 2;

  • Width is applied only from 480px so we can keep column width 100% width in mobile view.

Extend mixin to next level

We can add more options to this mixing for making its next level. We are not explaining how to do it in detail here. But the things we can achieve are like below:

  • Responsive breakpoints for different screen widths. Eg:
  • Let’s say we need to include another column in the footer – we can create a child without adding .block-group and also without MakeGrid Eg:
  • Can manage margin/padding from mixin for all the children or to individual child, Eg:

You can contact us for any Shopware Development assistance and also for setting this up in your organization.

Compiled CSS from our example

Enjoy developing Shopware themes as much as we do with these advanced styling methods.

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Aneesh ceo

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.