2017 © Pedro Peláez
 

cakephp-plugin twbs-cake-plugin

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

image

elboletaire/twbs-cake-plugin

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  • Tuesday, August 29, 2017
  • by elboletaire
  • Repository
  • 9 Watchers
  • 31 Stars
  • 20,885 Installations
  • CSS
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 1 Open issues
  • 16 Versions
  • 4 % Grown

The README.md

Bootstrap plugin for CakePHP 3.X

License ![Latest Stable Version][badge version] Total Downloads, (*1)

This plugin includes both less.js and less.php parsers and allows you to easilly deploy CakePHP applications with (Twitter) Bootstrap., (*2)

Since version 3.0.2 this plugin dropped its own helpers and components and added friendsofcake/bootstrap-ui as a composer requirement, so you will use all their classes instead., (*3)

It also contains bake templates that will help you starting twitter-bootstraped CakePHP webapps., (*4)

General Features

  • Parses less files using less.js and/or less.php.
  • LessHelper to easily parse files.
  • Bake templates.
  • Generic Bootstrap layout.
  • All the included utilities from BootstrapUI plugin.

Installation

Adding the plugin

You can easily install this plugin using composer as follows:, (*5)

composer require elboletaire/twbs-cake-plugin

After doing it, composer will ask you for a version. Checkout the package on packagist to know every available version., (*6)

Enabling the plugin

After adding the plugin remember to load it in your config/bootstrap.php file:, (*7)

Plugin::load('Bootstrap', ['bootstrap' => true]);

This will load the Less and BootstrapUI plugins for you., (*8)

If you preffer to do this manually, you can load them one by one:, (*9)

Plugin::load('Bootstrap');
Plugin::load('Less');
Plugin::load('BootstrapUI');

Configuration

After adding the plugin you can add the desired utilities:, (*10)

// AppController.php
public $helpers = [
    'Less.Less', // required for parsing less files
    'BootstrapUI.Form',
    'BootstrapUI.Html',
    'BootstrapUI.Flash',
    'BootstrapUI.Paginator'
];

Or, if loading them in the AppView:, (*11)

// AppView.php
public function initialize()
{
    $this->loadHelper('Less', ['className' => 'Less.Less']);
    $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
    $this->loadHelper('Form', ['className' => 'BootstrapUI.Form']);
    $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']);
    $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']);
}

Usage

There are two common usage ways when using twitter bootstrap and less:, (*12)

  • Directly using twitter bootstrap classes on your views.
  • Using custom classes on your views and then extending that classes to twitter bootstrap components.

For the first case you can directly load the layout included with this plugin and bake your views with the also included bake templates., (*13)

For the second case you'll need to create your own layout and create a stylesheet like the included one webroot/less/cakephp/styles.less., (*14)

This file extends the default baked views' styles so they have a CakePHP-Bootstrapped look and feel., (*15)

Themes

On both cases you can use the layout included with this plugin as a theme (right now there's only the default layout):, (*16)

// AppController or AppView
public function beforeRender(\Cake\Event\Event $event)
{
    $this->viewBuilder()->theme('Bootstrap');
}

Or as a layout:, (*17)

// AppController or AppView
public $layout = 'Bootstrap.default';

You can also specify it as a layout directly from your template files:, (*18)

// any .ctp Template file
$this->layout = 'Bootstrap.default';

You should use the Bootstrap layout if you wanna use less files. If you rather preffer using css files you may use the BootstrapUI layouts., (*19)

Last but not least, you can also copy that template to your Template/Layout folder and then extend the template from your view., (*20)

Read more about views on the CakePHP Cookbook., (*21)

BTW it's recommended that you copy all the required files to your src folder (specially for assets), even if you won't modify them., (*22)

Take in mind that if you're loading this plugin in a fresh CakePHP installation and you try to see the layout change in the home page, you won't see nothing. The home.ctp overwrites the layout to false, to ensure it's loaded as it has been designed., (*23)

Baking views

You can bake your views using the twitter bootstrap templates bundled with this plugin. To do so, simply specify the bootstrap template when baking your files:, (*24)

cake bake.bake [subcommand] --theme Bootstrap

Remember that you can also bake your views using BootstrapUI's bake templates. Take a look to its readme for more details., (*25)

Creating your own layout

Create a styles.less file on your webroot/less folder (also create that folder if it does not exist) containing this line:, (*26)

@import '../bootstrap/less/bootstrap.less';

Finally, load the less file from your view or layout:, (*27)

echo $this->Less->less('less/styles.less');

If you want to extend twitter bootstrap styles I recommend you to copy the bootstrap.less file to your less folder and customize it to your needs. For the variables.less create a custom-variables.less and load it just after variables.less in bootstrap.less file. Any variable defined in that file will overwrite the value defined in variables.less and your code won't break when updating (Twitter) Bootstrap., (*28)

If you'd like to see an example of this you can check the files included in webroot/less/cakephp specially made to extend the default CakePHP baked templates., (*29)

Utilities

This plugin "includes" the following utilities (all they come from other plugins):, (*30)

A note about Bootstrap's FlashComponent

The old Bootstrap FlashComponent used to have a close option that allowed you to define whether the flash alert would have a close button or not., (*31)

With BootstrapUI FlashHelper this works different. It looks for an alert-dismissible class (which is set by default) and, if defined, will show the close button., (*32)

For disabling the close button for the current Flash alert you can do:, (*33)

$this->Flash->{whatever}("Hello World", ['params' => ['class' => ['alert']]]);

// where {whatever} is any of the Bootstrap alert classes (danger, info, warning...)
$this->Flash->success("Hello World", ['params' => ['class' => ['alert']]]);

Note that the class param is defined as an array., (*34)

LessHelper

Used on your template or view to parse and load the compressed CSS., (*35)

The LessHelper is part of the less cakephp plugin. Check out all its details there., (*36)

Dependencies

Included dependencies

About versioning

This project started using the same versioning as CakePHP 3.X during its development stage. For this reason, I'll continue using this but reserving the latest version number for my versions., (*37)

This means that any version of this plugin with 3.0.X version number should be compatible with any CakePHP 3.0 version., (*38)

License

The MIT License (MIT)

Copyright 2013-2015 Òscar Casajuana (a.k.a. elboletaire)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

The Versions

29/08 2017

dev-master

9999999-dev https://github.com/elboletaire/twbs-cake-plugin

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin template cakephp bootstrap

01/02 2017

v3.4.1

3.4.1.0 https://github.com/elboletaire/twbs-cake-plugin

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin template cakephp bootstrap

01/02 2017

dev-develop

dev-develop https://github.com/elboletaire/twbs-cake-plugin

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin template cakephp bootstrap

14/12 2016

dev-f/update-readme

dev-f/update-readme

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

22/11 2015

v3.4.0

3.4.0.0

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

03/05 2015

v3.0.2

3.0.2.0

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

25/03 2015

v3.0.1

3.0.1.0

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

23/03 2015

v3.0.0

3.0.0.0

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

21/02 2015

v3.0.0-rc2

3.0.0.0-RC2

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php parser, helper and bake templates

  Sources   Download

MIT

The Requires

 

plugin cakephp bootstrap

11/01 2015

v3.0.0-rc1

3.0.0.0-RC1

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php parser, helper and bake templates

  Sources   Download

Apache-2.0

The Requires

 

plugin cakephp bootstrap

18/10 2014

v3.0.0-beta3

3.0.0.0-beta3

Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php parser, helper and bake templates

  Sources   Download

Apache-2.0

The Requires

 

plugin cakephp bootstrap

27/09 2014

v3.0.0-beta2

3.0.0.0-beta2

Twitter Bootstrap CakePHP Plugin with bundled less.php parser, helper and bake templates

  Sources   Download

Apache-2.0

The Requires

 

plugin cakephp bootstrap

24/08 2014

v3.0.0-beta1

3.0.0.0-beta1

CakePHP Twitter Bootstrap Plugin

  Sources   Download

Apache-2.0

The Requires

 

plugin cakephp bootstrap

03/08 2014

v3.0.0-alpha2

3.0.0.0-alpha2

CakePHP Bootstrap Plugin

  Sources   Download

The Requires

 

plugin cakephp bootstrap

13/07 2014

v3.0.0-alpha1

3.0.0.0-alpha1

CakePHP Bootstrap Plugin

  Sources   Download

The Requires

 

plugin cakephp bootstrap

06/10 2013

v2.0.1

2.0.1.0

CakePHP Bootstrap Plugin

  Sources   Download

The Requires

 

plugin cakephp bootstrap