Laravel Loading JavaScript libraries

Source: Internet
Author: User

An article:

Generating a Link to a Javascript File

Problem

You want your Blade template to the load an external JavaScript file.

Instead of using <script ...> directly, you want to does this with the HTML facade.

Solution

Use the HTML::script() method.

Just Pass the path to the JavaScript file.

{{Html::script (' Js/functions.js ')}}

This produces the following HTML code.

<scriptsrc="Http://your.url/js/functions.js"></script>   

If the file path you pass is ' t a complete URL, Laravel'll use your application's URL to build a complete URL.

You can pass additional attributes in an array as the second argument.

{{Html::script (' js/functions.js ', Array (' async ' = ' async ')}}}

The attributes is added to the script tag as the result below illustrates.

<scriptAsync="Async"src="Http://your.url/js/functions.js"></script >      
Discussion

The type attribute of <script> tags is optional with HTML5.

But if your Web page was still HTML 4.01, you should add the ' to the ' "type" => "text/javascript" attributes you pass this method.

Transferred from: http://laravel-recipes.com/recipes/183

Written in the previous words:

1. If you need to use the Blade template engine

The 2.css JS image folder is built under the public directory of Laravel.

3. The generated path is the relative path by default

A: Load the CSS file (replace the normal link with the following format)

{{Html::style (' Css/custom.css ')}}

The resulting appearance in the page is as follows

<link media= "All" type= "text/css" rel= "stylesheet" href= "http://local.lv.com/css/ Custom.css ">

B: Load the JS file (replace the normal script with the following format)

{{Html::script (' Js/custom.js ')}}

The resulting appearance in the page is as follows

<script src= "Http://local.lv.com/js/custom.js" ></script>

C: Add images to the page (also remove the IMG tag)

{{html::image (' Images/hot_1.gif ')}}

What the build looks like

src= "Http://local.lv.com/images/c_4.gif" >

If you want to customize the IMG (add alt or title and other attributes), then nothing to change, the direct use of on it, if you need to configure Apache, Set the DocumentRoot directly to the public directory, because the relative paths are used .

Transferred from: http://www.cnblogs.com/debmzhang/p/3500429.html

Laravel Loading JavaScript libraries

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.