Laravel 5 uses Htmlbuilder and Url::asset () to introduce CSS and JS files inside or outside the station

Source: Internet
Author: User
The introduction of in-station or out-of-site CSS and JS files is a basic requirement, Laravel 5 provides a variety of ways to introduce CSS and JS, today we will discuss this issue.

1, Htmlbuilder

Before Laravel 5 We used the built-in Htmlbuilder to add styles and script files, but Laravel 5 removed the Htmlbuilder from the core, so Html::style () was no longer valid. If you want to continue using Laravel 5, you need to manually introduce illuminate/html to this package.

We still install through composer:

Composer require illuminate/html 5.*

After the installation is complete, you need to register the service provider to the providers array in config/app.php:

Illuminate\html\htmlserviceprovider::class,

Register the façade to the aliases array at the same time:

' Html ' = Illuminate\html\htmlfacade::class, ' Form ' = Illuminate\html\formfacade::class,

Next, you can use the following methods to introduce CSS and JS files in the view file:

{!! Html::style (' Css/style.css ')!} {!! Html::script (' Js/script.js ')!}

Note: The site files are by default relative to the Web root directory, which is the public directory

If you want to introduce an off-site file, you can do so:

{!! Html::style ('//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css ')!} {!! Html::script ('//code.angularjs.org/1.2.13/angular.js ')!}

2, Url::asset ()

In addition, you can use the asset () method on the built-in URL class to introduce CSS and JS files.

Introduction of In-Station CSS and JS:

 
  

Note: The default is relative to the Web root directory, which is the public directory

Introduction of Off-site CSS and JS:

 
  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.