Skip to content

Instantly share code, notes, and snippets.

@mCzolko
Last active April 23, 2019 04:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mCzolko/5282549 to your computer and use it in GitHub Desktop.
Save mCzolko/5282549 to your computer and use it in GitHub Desktop.
How to integrate Font Awesome to Symfony 2

Integration

It's easy to integrate Font Awesome into Symfony2 (Twitter Bootstrap, or even use it on its own).

Composer

Add those lines to composer.json

{
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "fontawesome/fontawesome",
        "version": "3.0.2",
        "dist": {
          "url": "https://github.com/FortAwesome/Font-Awesome/archive/v3.0.2.zip",
          "type": "zip"
        }
      }
    }
  ],
  "require": {
    "fontawesome/fontawesome": "3.0.2"
  }
}

Then php composer.phar update for install assets.

Fonts

Create symlink to font files located at vendor folder like this:

cd web
ln -s ../vendor/fontawesome/fontawesome/font/ font

Assest

And those lines to config.yml

assetic:
  filters:
    less:
      node:       /usr/local/bin/node
      node_paths: [%kernel.root_dir%/../node_modules]
      apply_to:   "\.less$"
    cssrewrite: ~
  assets:
    fontawesome_css:
      inputs:
        - %kernel.root_dir%/../vendor/fontawesome/fontawesome/less/font-awesome.less
      filters:
        - less
        - cssrewrite
      output: css/fontawesome.css
    fontawesome_IE7_css:
      inputs:
        - %kernel.root_dir%/../vendor/fontawesome/fontawesome/less/font-awesome-ie7.less
      filters:
        - less
        - cssrewrite
      output: css/fontawesome_IE7.css

Basic template layout

Append stylesheets at bottom of your <head> tag.

<head>
  ...
  <link rel="stylesheet" href="{{ asset('css/fontawesome.css') }}">
  <!--[if IE 7]>
  <link rel="stylesheet" href="{{ asset('css/fontawesome_IE7.css') }}">
  <![endif]-->
</head>
@martijngastkemper
Copy link

Font Awesome is available via Packagist. So composer require fortawesome/font-awesome is an easier way to install Font Awesome.

@cptsafeguard
Copy link

I have downloaded fontawesome into vendor directory "I have no access to ssh console" so my fontawesome directory is vendor/fontawesome/fontawesome/less/ I made what is done in here but it show 404 error on GET http://anunciogoogleadwords.com.br/css/fontawesome.css in chrome developer tools

@edgarshurtado
Copy link

@martijngastkemper the name of the vendor has changed in Packagist. Now is components/font-awesome .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment