-1

This is the content of my base.html.twig file:

<html lang="en" class="no-js">
<head>
    <title>{% block title %}Welcome!{% endblock %}</title>
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    {% block stylesheets %}
        <link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css">
    {% endblock %}

</head>

This is the path of my file: C:\xampp\htdocs\myproject\app\Resources\assets\css\bootstrap.css.

I am note sure if my path is correct I am a totally newbie to this. Can someone point me and explained step by step how can include a css file ? thx in advance

[UPDATE] Here is my structure of my projectenter image description here

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59

2 Answers2

1

In project folder add to src/AppBundle(or name of your bundle)/Resources/public/css/bootstrap.css

and then in twig template do this:

{{asset('bundles/name_of_your_bundle/css/bootstrap.css')}}

This will generate url for your file in src/your_bundle/Resources/public/css/bootstrap.css

I suggest you to read this blog: http://tutorial.symblog.co.uk/index.html There is series how to create blog in symfony2.

marcin.g
  • 365
  • 1
  • 2
  • 14
  • can you check my update ? I did what you suggested and still my css file is not loaded – Attila Naghi Jul 09 '16 at 17:26
  • @Chester In terminal go to your project folder and type: `php app/console assets:install --symlink` then check if you have your file in `web/bundles/app/...` – marcin.g Jul 09 '16 at 17:31
  • Can you help me executing this on windows ? this command doesn;t work on windows – Attila Naghi Jul 09 '16 at 17:33
  • Could not open input file: app/console this is what i got and the php variables are set in the environments variables – Attila Naghi Jul 09 '16 at 17:36
  • Your probably have to add php to system path here is a link how do it: http://stackoverflow.com/questions/7307548/how-to-access-php-with-the-command-line-on-windows – marcin.g Jul 09 '16 at 17:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116883/discussion-between-chester-and-marcin-g). – Attila Naghi Jul 09 '16 at 17:39
0

firstly, including a css file has got nothing to do with php or symphony

 <link href="css\bootstrap.css" rel="stylesheet" type="text/css">

if you are using this to include the css file then your php file must be in the assets folder, if its outside any other folder, just say its in the app folder then you need to include those folders as well in the path.

<link href="Resources\assets\css\bootstrap.css" rel="stylesheet" type="text/css">

as you said you are totally newbie, and i see you are trying symphony. i would like to advice you to start with HTML and CSS, then PHP and and move to symphony after that. If you do not want to face any problem in the future.

Mukul Chauhan
  • 120
  • 1
  • 1
  • 10
  • thx for the answer but I think I should use assets. The fact is that I do not know how. By including the css just like that, it doesn;t solve my problem:) – Attila Naghi Jul 09 '16 at 17:29
  • sure bro, i never said you should not use assets :), we all have our style of coding. – Mukul Chauhan Jul 09 '16 at 19:58