0

I have added css on custom phtml file using:

<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/banner.css')?>">

and placed the CSS file in folder: Magento_Theme/web/css When I load page and view the page content source it shows the CSS path as:

<link rel="stylesheet" type="text/css" href="http://xyz/magento-2/pub/static/version1530249778/frontend/Magento/mytheme/en_US/css/banner.css">

But not created any file on pub/static folder. I have cleared the cache and run the upgrade command.

Thanks

1 Answer 1

0

If your css file in Magento_Theme folder then you should follow this code:

<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('Magento_Theme::css/banner.css')?>">

I hope it will works.

6
  • <?php echo $block->getViewFileUrl('css/banner.css')?> why it not created on path mytheme/en_US/css/ ? Commented Jun 29, 2018 at 6:13
  • I want to create the css on path mytheme/en_US/css/ Commented Jun 29, 2018 at 6:14
  • Then you should write like this: <link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/banner.css')?>"> & your css file in app/design/frontend/Vendor_Name/Theme_Name/web/css/file_name.css. folder. Commented Jun 29, 2018 at 6:19
  • After that you need to setup upgrade & deploy static content data. Commented Jun 29, 2018 at 6:21
  • M2 very complex as compare to old magento, anyway thanks Commented Jun 29, 2018 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.