duanpei8853 2016-06-24 05:18
浏览 307
已采纳

如何在laravel中添加动态js和css的布局?

Recently I sarted to learn laravel framework. I installed Laravel 5 using composer and I need to know how to include a constant layout where I can put up gobal css and js links.

  • 写回答

1条回答 默认 最新

  • dpklt4291 2016-06-24 05:26
    关注

    Write routes

    Route::get('/', function()
    {
        return View::make('pages.home');
    });
    Route::get('about', function()
    {
        return View::make('pages.about');
    });
    Route::get('projects', function()
    {
        return View::make('pages.projects');
    });
    Route::get('contact', function()
    {
        return View::make('pages.contact');
    });
    

    Make sure you follow this folder structure

    - app
    -- views
    --- layouts
    ------- default.blade.php
    ------- sidebar.blade.php
    --- pages
    ------- home.blade.php
    ------- about.blade.php
    ------- projects.blade.php
    ------- contact.blade.php
    --- includes
    ------- head.blade.php
    ------- header.blade.php
    ------- footer.blade.php
    ------- sidebar.blade.php
    

    Include following in head.blade.php

    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="author" content="Scotch">
    <title>Super Cool Layouts</title>
    <!-- load bootstrap from a cdn -->
    <link rel="stylesheet" href="<?php echo asset('css/style.css'); ?>">
    <script type="text/javascript" src="<?php echo asset('js/main.js'); ?>"></script>
    

    Write header and fooder in header.blade.php and footer.blade.php

    <div class="navbar">
        <div class="navbar-inner">
            <a id="logo" href="/">Single Malt</a>
            <ul class="nav">
                <li><a href="/">Home</a></li>
                <li><a href="/about">About</a></li>
                <li><a href="/projects">Projects</a></li>
                <li><a href="/contact">Contact</a></li>
            </ul>
        </div>
    </div>
    

    Finally create the layout in default.blade.php

    <!doctype html>
    <html>
    <head>
        @include('includes.head')
    </head>
    <body>
    <div class="container">
    
        <header class="row">
            @include('includes.header')
        </header>
    
        <div id="main" class="row">
    
                @yield('content')
    
        </div>
    
        <footer class="row">
            @include('includes.footer')
        </footer>
    
    </div>
    </body>
    </html>
    

    To include the layout use this in home.blade.php

    @extends('layouts.default')
    @section('content')
        i am the home page
    @stop
    

    I found a complete tutorial over here Include js and css file in laravel using blade

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件