PHPackages                             gdarko/twitter-bootstrap-grid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gdarko/twitter-bootstrap-grid

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

gdarko/twitter-bootstrap-grid
=============================

Easily generate valid Twitter Bootstrap 3 grid using PHP loops

1.2(10y ago)41.7kMITPHP

Since Apr 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/gdarko/twitter-bootstrap-grid)[ Packagist](https://packagist.org/packages/gdarko/twitter-bootstrap-grid)[ RSS](/packages/gdarko-twitter-bootstrap-grid/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

TwitterBootstrapGrid
====================

[](#twitterbootstrapgrid)

This is a lightweight PHP script that makes easy generating a `Twitter Bootstrap 3` grid using PHP. It uses the default Twitter bootstrap classes like `.row` and `.col-*` to generate the grids. It's pretty straightforward to use, it allows to specify how many columns per row to have for each Bootstrap viewport (xs, sm, md, lg)

Installation
============

[](#installation)

### Composer

[](#composer)

You can install it with composer, you need to have composer installed and you are good to go!

```
composer require gdarko/twitter-bootstrap-grid

```

### I don't know what Composer is

[](#i-dont-know-what-composer-is)

I don't recommend this way but you can always download the latest release and require the class.

```
require "twitter-bootstrap-grid/src/TwitterBootstrapGrid.class.php"
```

How to Use
==========

[](#how-to-use)

Few examples how to use the script:

### Example #1

[](#example-1)

You can use the addColumn method to add a column to the grid and later build. The constructor accepts array of columns as a second parameter

```
use gdarko\Tools\TwitterBootstrapGrid;

$grid = new TwitterBootstrapGrid( $row_columns = 4 );
$columns = ["1", "2", "3", "4", "5", "6", "7"];
foreach($columns as $column){
    $grid->addColumn($column);
}
echo $grid->build();
```

### Example #2

[](#example-2)

You can use the setTotalRowColumns method to change the number of columns for a given viewport per row. In this example we are using 2 columns for "lg" classes. So one of the column classes will be `.col-sm-6`

```
use gdarko\Tools\TwitterBootstrapGrid;

$columns = ["1", "2", "3", "4", "5", "6", "7"];
$grid = new TwitterBootstrapGrid( $row_columns = 4, $columns );
$grid->setTotalRowColumns(2, "lg");
echo $grid->build();
```

### Example #3

[](#example-3)

You have a large templates that need to be printed? No problem. You can combine it with output buffering.

```
use gdarko\Tools\TwitterBootstrapGrid;

$grid = new TwitterBootstrapGrid( $row_columns = 3 );
foreach($objects as $object){
    ob_start();
    include('templates/display-orange.php');
    $content = ob_get_clean();
    $grid->addColumn($content);
}
$grid->setTotalRowColumns(3, "sm");
echo $grid->build();
```

### Example #4

[](#example-4)

Do you want to build a fluid grids? For example you have 3 columns per row on large screens and two columns per row on mobiles. It's not that easy with the default Bootstrap aproach. This snippet will make your life easier.

```
use gdarko\Tools\TwitterBootstrapGrid;

$grid = new TwitterBootstrapGrid();
//Demo data, ignore it
for($i = 0; $i < 9; $i++){
    $grid->addColumn($i . "");
}

$grid->setCustomTotalRowColumns($grid->getColumnsCount());
$grid->setCustomColumnClass("col-lg-4", "lg");
$grid->setCustomColumnClass("col-xs-6", "xs");

echo $grid->build();
```

Pretty straightforward, huh?

Changelog
=========

[](#changelog)

### v1.2

[](#v12)

-Fix: Missing closing when the last row has less columns than specified number of columns per row.

### v1.1

[](#v11)

- Fluid grids support ( see Example #4 )
- Updated constructor ( no need to require $row\_column\_lg in case we are creating fluid grids )

### v1.0

[](#v10)

- Integration with Composer
- Integration with PSR-4

Development
===========

[](#development)

Want to contribute? Great!

If you found a bug or want to contribute to the script feel free to create pull requests to make it even better!

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

3

Last Release

3721d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/092968da21d868077ffac225d195f167f19435d61409f8ec656136c6f3d6f197?d=identicon)[gdarko](/maintainers/gdarko)

---

Top Contributors

[![gdarko](https://avatars.githubusercontent.com/u/5760249?v=4)](https://github.com/gdarko "gdarko (19 commits)")

---

Tags

phpgridtwitterbootstrapscript

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gdarko-twitter-bootstrap-grid/health.svg)

```
[![Health](https://phpackages.com/badges/gdarko-twitter-bootstrap-grid/health.svg)](https://phpackages.com/packages/gdarko-twitter-bootstrap-grid)
```

###  Alternatives

[cwspear/bootstrap-hover-dropdown

An unofficial Bootstrap plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience.

1.2k155.6k](/packages/cwspear-bootstrap-hover-dropdown)[slywalker/twitter_bootstrap

CakePHP Bootstrap (for Twitter) Plugin

28732.2k](/packages/slywalker-twitter-bootstrap)[mediawiki/chameleon-skin

A highly flexible MediaWiki skin using Bootstrap 5

12484.1k2](/packages/mediawiki-chameleon-skin)[spoonx/sxbootstrap

A twitter bootstrap module for ZF2 (zend framework 2) based on rwoverdijk/assetmanager

3010.7k1](/packages/spoonx-sxbootstrap)[eftec/minilang

A mini scripting language for php

113.2k2](/packages/eftec-minilang)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
