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:

  • 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:

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 the parent (. header) with. block-group
  • Looping all child and extending child with. block
  • The child must be a class without a dot(.)

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:
  • .makeGrid( @child: logo 2, navigation 8, search 2; @GridXS: logo 12, navigation 12, search 12; @GridSM: logo 4, navigation 6, search 2; @GridMD: logo 2, navigation 8, search 2; @GridLG: logo 2, navigation 8, search 2; @GridXL: logo 2, navigation 8, search 2; );
  • 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
  • .makeChild( @class: search; @column: 4; );
  • Can manage margin/padding from mixin for all the children or to individual child, Eg:
  • .makeGrid( @child: logo 2; @padding: 0; @margin: 0; @childMargin: 0; @childPadding: 0; );

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.

Originally published at https://www.2hatslogic.com on March 26, 2019.

2Hats Logic is a technology service company provide customized web and mobile application development.