Biguá Biguá - 2 months ago 36
Twig Question

Setup twitter bootstrap, in slim php, after downloading via composer?

I've installed twitter bootstrap via composer and don't have any idea how to reference it in a twig view. I suppose there's a namespace for it but I don't get it.

In this similar question : How to setup bootstrap after downloading via composer? they use artisan to solve this but how to do this in slim php ?

My folder structure:

├── app
│   ├── controllers
│   ├── models
│   └── templates
├── composer.json
├── composer.lock
├── config
│   └── local.php
├── logs
│   ├── README.md
│   └── app.log
├── public
│   ├── css
│   └── index.php
├── src
│   ├── dependencies.php
│   ├── middleware.php
│   ├── routes.php
│   └── settings.php
└── vendor
├── autoload.php
├── bin
├── composer
├── container-interop
├── doctrine
├── illuminate
├── monolog
├── nesbot
├── nikic
├── paragonie
├── pimple
├── psr
├── slim
├── symfony
├── twbs
└── twig


Composer.json file:

{
"name": "slim/slim-skeleton",
"description": "A Slim Framework skeleton application for rapid development",
"keywords": [
"microframework",
"rest",
"router",
"psr7"
],
"homepage": "http://github.com/slimphp/Slim-Skeleton",
"license": "MIT",
"authors": [
{
"name": "Josh Lockhart",
"email": "info@joshlockhart.com",
"homepage": "http://www.joshlockhart.com/"
}
],
"require": {
"php": ">=5.5.0",
"slim/slim": "^3.1",
"monolog/monolog": "^1.17",
"illuminate/database": "~5.1",
"slim/twig-view": "^2.1",
"twbs/bootstrap": "^3.3"
},
"autoload": {
"psr-4": {
"App\\Models\\": "app/models",
"App\\Controllers\\": "app/controllers"
}
}
}

Answer

You could setup a composer hook to automatically copy the file to your public directory:

{
  "scripts": {
    "post-update-cmd": "cp vendor/twbs/bootstrap/dist/css/bootstrap.css public/",
    "post-install-cmd": "cp vendor/twbs/bootstrap/dist/css/bootstrap.css public/"
  }
}

This should go into composer.json.
Note: Not tested but should work.

Comments