Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6358703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:25:21+00:00 2026-05-24T23:25:21+00:00

How to include .css and .js files in a php file (index.html.php for example)

  • 0

How to include .css and .js files in a php file (index.html.php for example) on Symfony? (I’m using Symfony2 if that matters), I read that I must include the src/link within an asset function like follow:

<link href="<?php echo $view['assets']->getUrl('MyStyle.css') ?>" rel="stylesheet" type="text/css" />

<link href="<?php echo $view['assets']->getUrl('buttons.css') ?>" rel="stylesheet" type="text/css" />

Neither that nor the ordinary of php, worked with me.
Update: css files locate on \Bundle\Resources\public\css

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:25:22+00:00Added an answer on May 24, 2026 at 11:25 pm

    You have two options:

    without using assetic:

    If your assets are in src/Your/Bundle/Resources/public/, you have to call ./app/console assets:install --symlink web/ to create a symlink from web/bundle/yourbundle to src/Your/Bundle/Resources/public/ so that they are accessible from web (alternatively you could do ./app/console assets:install web/ to copy the files directly, without symlink.

    Then you could do this:

    <link href="<?php echo $view['assets']->getUrl('/bundle/yourbundle/css/MyStyle.css') ?>" rel="stylesheet" type="text/css" />
    

    using assetic:

    With assetic you don’t need to install/copy the files, assetic will do it for you:

    <?php foreach ($view['assetic']->stylesheets(
        array('@YourBundle/css/MyStyle.css')) as $url): ?>
    <script type="text/javascript" src="<?php echo $view->escape($url) ?>"></script>
    <?php endforeach; ?>
    

    See http://symfony.com/doc/current/cookbook/assetic/asset_management.html (click on the PHP tab on the code samples).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file that i include in other php files. This php
We include the CSS file via standard HTML STYLE tag. Then we need the
i have the strangest bug. in my php file i include several php files:
I have a website that has an index.php, a few simple .html pages and
So I have this index.php page: <?php include main.php; ?> <html> <head> <link rel=stylesheet
I have an index.php file in the top level with other files such as
Is it possible to include one CSS file in another?
Here's my directory structure: -root --docs ---doc1.php --includes ---header.php ---footer.php ---css.css --index.php In my
I've just started using codeigniter and wanted to include some external css in my
I have few import statements in my index.php file. The website is bit slow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.