I've already installed Laravel Blade Highlighter..
#yield #section #endsection is not working, just a plain white text..
My views are working properly.. I can browser them okay..
Here's my code:
web.php:
Route::get('/', 'PagesController#index');
Route::get('/about', 'PagesController#about');
Route::get('/services', 'PagesController#services');
pagesController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PagesController extends Controller
{
public function index(){
return view('pages.index');;
}
public function about(){
return view('pages.about');
}
public function services(){
return view('pages.services');
}
}
app.blade.php
<h1>This is the laravel</h1>
#yield('content')
index.php:
#extends('layouts.app')
#section('content')
<h1>Welcome to Laravel</h1>
<p>this is a content</p>
#endsection
The answer is I should close all open tab on my sublime text..
And index.php, about.php and services.php should be index.blade.php, about.blade.php and services.blade.php
Related
I am trying to create simple application using Laraver(8) Blade, I am a complete beginner in Blade, I want to rednder extended view in my template, but it doesn't works, also it doesn't throwing any errors, The page is refreshed my view not showing, what i am doing wrong?
main layout:
<!DOCTYPE html>
<html>
<head>
#include('layout.header')
#stack('css')
</head>
<body id="body">
<div class="blackscreen"></div>
<div class="blackscreen2"></div>
#yield('content')
<script src="{{url('js/developer.js')}}"></script>
#stack('js')
</body>
</html>
template:
#extends('layout.main')
#section('content')
<h1>hello</h1>
#endsection
route:
Route::get('/', function () {
return view('layout/main');
});
Route::get('/test2', function () {
return view('layout/main');
});
this is my file structure
if you save your template into resources/views/template.blade.php,
you should call view method like this:
Route::get('/', function () {
return view('template');
});
if you save your template into other folder inside resources/views, like resources/views/test/template.blade.php,
you should call view method like this:
Route::get('/', function () {
return view('test.template');
});
Hi all I have problame with my form I am writing html form but its error
and this is my route code
Route::get('course','CourseController#index');
and this is my CourseController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class CourseController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('course.create');
}
and this is my view course/create.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="">
</head>
<body>
<div class="container">
{!! Form::open(array('route' => 'course.store')) !!}
<input type="text"><br>
<input type="password"><br>
{!! Form::close() !!}
</div>
</body>
</html>
and error:
Whoops, looks like something went wrong.
1/1 FatalErrorException in 818f720d4e075893d8198d2b0ff02e25 line 9: Class 'Form' not found
Help me please
With Laravel 5.* the Form & Html have been deprecated. Check out uprade guide (search Form & HTML Helpers).
1. Install laravelcollective/html
composer require laravelcollective/html
2. Add the Form and HTML facades and service provider.
Edit config/app.php and add this line to the 'providers' array:
'Collective\Html\HtmlServiceProvider',
Next, add these lines to the 'aliases' array:
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
This is my page in View.
<!DOCTYPE html>
<?php $this->load->view('partials/page_head');?>
<body>
<div class="wrapper">
<header>
<div class="logo">Logo</div>
</header>
<?php $this->load->view('partials/menu');?>
<div id="content">
<?php $this->load->view('partials/', $subview); ?>
</div>
<footer>© 2012 Codeigniter.tv</footer>
</div>
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
</body>
</html>
This is my menu page inside partials folder.
<menu>
<ul>
<li>Listing</li>
<li>Detail</li>
</ul>
</menu>
Below is the controller part.
<?php
class Example extends CI_Controller {
public $data = array('subview' => 'Oops, forgot to set a subview');
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function listing() {
$this->data['subview'] = 'listing';
$this->load->view('layouts/layout', $this->data);
}
public function detail() {
$this->data['subview'] = 'detail';
$this->load->view('layouts/layout', $this->data);
}
}
I could not display the content in the file 'listing.php' which is in partials folder. When i run the project in localhost it saying not found. Can anyone help me to correct my problems.
modify views as bellow.
<!DOCTYPE html>
<?php $this->load->view('partials/page_head');?>
<body>
<div class="wrapper">
<header>
<div class="logo">Logo</div>
</header>
<?php $this->load->view('partials/menu');?>
<div id="content">
<?php $this->load->view('partials/'.$subview); ?>
</div>
<footer>© 2012 Codeigniter.tv</footer>
</div>
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>') </script>
</body>
</html>
modify your menu file as below
<menu>
<ul>
<li>Listing</li>
<li>Detail</li>
</ul>
</menu>
I'm trying to understand laravel's basic blade template engine, but I can't seem to get past a basic example. My blade template is not loading .It only show the white screen but when I remove the hello.blade.php to hello.php it works .Any suggestion?
Routes.php
Route::get('/', 'PagesController#home');
PagesController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function home()
{
return Views('hello');
}
}
hello.blade.php
<html>
<head>
<title>Hello World</title>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Starting to learn Laravel 5</div>
</div>
</div>
</body>
</html>
There is no Views helper. It's called view:
return view('hello');
Well, I had the same "white screen problem". And the blade docs in laravel is so confused. Then, try this:
Create a layout, lets say template.blade.php:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Starting to learn Laravel 5</div>
#yield('view_content')
</div>
</div>
</body>
Create a simple view that you want to wrap into the template, lets say hello.blade.php:
#extends('template')
#section('view_content')
This is my view content
#stop
Now, in your controller just call the view instead the layout:
public function home(){
return view('hello');
}
I'm not sure how it is working regardless of the extension as in your controller the syntax is incorrect. You return the view not Views... return view('hello'). You should technically see something like the following:
FatalErrorException in PagesController.php line 18:
Call to undefined function App\Http\Controllers\Views()
Even if app_debug is false you should see Whoops, looks like something went wrong.
I got this when I made a typo like so:
return views('abc');
instead of
return view('abc');
That extra s was killing everything.
I'm new in CodeIgniter. I want to create Master Page or Layout with base style that will be contain Menu, footer and etc. I don't want to write repeating content in all pages and load it automatically for all pages. For example, I can create Master Page in asp.net or Layout in asp.net mvc. I'm sure I can do it in CodeIgniter.
lets assume you have an html page
<html>
<head>
<title> Hello World </title>
</head>
<body>
<div id="menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</div>
<div id="main-content">
<!-- this is the dynamic part -->
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
you could split it into
1- header
2- menu
3- main content
4- footer
you basically put
<html>
<head>
<title> Hello World </title>
</head>
<body>
in one view called "view_header"
then you put
<div id="menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</div>
<div id="main-content">
in a view called "view_menu"
and then you put
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
in a view called "view_footer"
then in your controller
$this->load->view('view_header');
$this->load->view('view_menu');
$this->load->view('YOUR_VIEW');
$this->load->view('view_footer');
The other solution, which I see is better: create a view called view_template.php
<html>
<head>
<title> Hello World </title>
</head>
<body>
<div id="menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</div>
<div id="main-content">
<?php $this->load->view($content); ?>
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
in the controller lets say you want to call a view called About
$data = array('content'=>'about');
$this->load->view('view_template',$data);
Dynamic Layout
You would create a new Controller with a public $template variable
Your extended Controller will then inherit the $template variable from the Master Controller.
MY_Controller
class MY_Controller extends CI_Controller
{
public $template=null;
public function __construct()
{
if(is_null($this->template)){
$this->template = 'layouts/default';
}
}
}
Admin_controller
class Admin_Controller extends MY_Controller
{
public function __construct()
{
//Still inherits from MY_Controller
//this time, any controller extending Admin_Controller
//will point to 'views/layouts/admin'
if(is_null($this->template)){
$this->template = 'layouts/admin';
}
}
}
-
class User extends MY_Controller
{
public function index()
{
//$this->template is inherited
//from MY_Controller
//which point to 'views/layouts/default'
//We can also load a view as data
//ie no master layout, INTO our master layout
//note we don't pass $this->template
//and set the third param as true
$dynamic_sidebar = $this->load->view('views/sidebar/dynamic', array(
'data' => 'some_data'
), true);
return $this->load->view($this->template, array(
'partial' => 'users/index' //partial view,
'dynamic_sidebar' => $dynamic_sidebar
));
}
}
Views/Layouts/default
<body>
//load the main view
//in our example we have also loaded
//a dynamic sidebar with this view
<?php $this->load->view($partial); ?>
<?php $this->load->view($dynamic_sidebar); ?>
//load a static view
//views/sidebar/static
<?php $this->load->view('sidebar/static'); ?>
</body>
Following the idea of a master page in Laravel, we can do this:
Controller code
$this->load->view('show');
View "show.php"
Set values for master page and then pass the variables to master page. Keep your master page codes inside ob_start() & ob_get_clean().
<?php $page_title = "My first page"; ?>
<?php ob_start(); ?>
Your header stylesheet links and scripts
<?php $page_header = ob_get_clean(); ?>
<?php ob_start(); ?>
<div>
<h1>This is a Header</h1>
<?php $this->load->view('Partials/list'); ?>
</div>
<?php $page_content = ob_get_clean(); ?>
<?php ob_start(); ?>
Your footer html or scripts
<?php $page_footer = ob_get_clean(); ?>
<?php $this->load->view('Layout/app',array(
'page_title' => $page_title,
'page_header' => $page_header,
'page_content' => $page_content,
'page_footer' => $page_footer
)); ?>
Partial view "Partials/list.php"
In case you don't want your code to be crowded. You can create some partial views to keep things simple.
<ul>
<li>LIst item 1</li>
<li>LIst item 2</li>
<li>LIst item 3</li>
</ul>
Master Page "Layout/app.php"
<html>
<head>
<title><?= v($page_title) ?></title>
<?= v($page_header) ?>
</head>
<body>
<?= v($page_content) ?>
<?= v($page_footer) ?>
</body>
</html>
<?php
function v(&$var)
{
return isset($var) ? $var : '';
}
So that will genarate code:
<html>
<head>
<title>My first page</title>
Your header stylesheet links and scripts
</head>
<body>
<div>
<h1>This is a Header</h1>
<ul>
<li>LIst item 1</li>
<li>LIst item 2</li>
<li>LIst item 3</li>
</ul>
</div>
Your footer html or scripts
</body>
</html>
What we probably do is separate view files for header, menu, footer, etc.. that is common for all pages. And include them inside each view. like
$this->view('header');
$this->view('menu');
//Some specific content
$this->view('footer');
If you need same functionality without copying the above to all views, you need to create a function in your controller as follows:
private function myviewfunction($current_view)
{
$this->load->view('header');
$this->load->view('menu');
$this->load->view($current_view);
$this->load->view('footer');
return NULL;
}
and call this function in all your pages (methods)
$this->myviewfunction('about'); //About is the specific view for the method