OK, it has taken me forever (since Friday) to configure everything related to Laravel, mcrypt & PHPStorm and now I am only trying to display a simple form field - it's completely blank
#section('content')
{{ Form::open() }}
{{ Form::label('username', 'Username:') }}
{{ Form::text('username') }}
{{ Form::close() }}
#stop
When I inspect element, no form exists and there are no errors - WTF?
My file is called index.blade.php
Within my routes.php:
Route::get('/', function()
{
return View::make('index');
});
The documentation makes it look so easy
As lagbox says you probably just need to extend a layout. So you have master.blade.php (in a layouts folder in your view probably) which has your HTML head/body tags etc:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/dist/css/app.min.css" rel="stylesheet">
</head>
<body>
#yield('content')
<script src="/dist/js/app.min.js"></script>
</body>
</html>
Then you have your index.blade.php file which will have something like this:
#extends('layouts.master')
#section('content')
{{ Form::open() }}
{{ Form::label('username', 'Username:') }}
{{ Form::text('username') }}
{{ Form::close() }}
#stop
Take a look at the Laravel Blade documentation for more info: Laravel Blade
Related
Dear Excellent developes.
I'm trying to duild static web site with Hugo (Netlify CMS).
I wanna build from scratch, if I can;-) ( I designed the site by myself. SO I wanna write sass from scratch).
But, sass files aren't read successflly.
Do you solve the problem?
I checked there pages to solve it , But I couldn't
https://gohugo.io/hugo-pipes/scss-sass/
https://discourse.gohugo.io/t/custom-css-throws-type-nil-not-supported-in-resource-transformations/19942
the structure of this Web site
Basically, there are not many changes from Hugo install.
layouts/index.html // I write there the following code.
resources/_gen/assets/sass/main.scss // I wrote simple css to this file → html {background: yellow;}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
{{ $sassTemplate := resources.Get "sass/main.scss" }}
{{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}
<link rel="stylesheet" href="{{ $style.relURL }}">
</head>
<body>
<h1>Nice. It's looking good already.</h1>
<ul>
{{ range (where .Pages "Section" "blog") }}
<li>
<a href="{{ .RelPermalink }}">
{{ .Title }}
</a>
</li>
{{ end }}
</ul>
</body>
</html>
Error messages
Rebuild failed:
Failed to render pages: render of "home" failed: "/Users/RPOISITORY-NAME/layouts/index.html:11:40": execute of template failed: template: index.html:11:40: executing "index.html" at <resources.ExecuteAsTemplate>: error calling ExecuteAsTemplate: type <nil> not supported in Resource transformations
↓
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
{{ $sassTemplate := resources.Get "sass/main.scss" }}
{{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}
<link rel="stylesheet" href="{{ $style.relURL }}">
</head>
hugo v0.81.0+extended darwin/amd64 BuildDate=unknown
Thanks in advance.
Your .scss files must be in the assets folder at the root of your project, and not in the sub-folder resources/_gen/assets.
I wrote a post in french on the topic, maybe you can grab some hints / use a translator
I am trying to retrieve data from my database and show it in my view but there I get an error.
Here is my controller
public function index()
{
$Page=Superior::all();
return view('Myview.Firstpage')->with('Task',$Page);
}
And this is where I assign in the view
<body>
<p>this is our first page </p>
{{ $Task }}
</body>
</html>
but this task is creating error and it says that the Task is an undefined variable my whole page looks like this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>This is our first page </title>
</head>
<body>
<p>this is our first page </p>
{{ $Task }}
</body>
</html>
Superior is the name of my model from which I want to retrieve my data.
My routes files in web.php is
<?php
Route::get('First',function(){
return view('Myview.Firstpage');
});
i am learning laravel
In the index method of your controller
public function index()
{
return view('Myview.Firstpage')->with('tasks',Superior::all());
}
Keep in mind that the all() method returns a collection which you want to loop through in your view.
In your view, you should have:
#foreach($tasks as $task)
{{ $task->title }}
#endforeach
You need to also update your route to make use of the controller:
Route::get('/', 'TaskController#index');
You could visit https://laravel.com/docs/5.8/collections#method-all to learn more about collections.
Hi please try to pass you variable to view like this:
$Tasks = Superior::all();
return view('Myview.Firstpage', compact('Tasks'));
And then use a loop in your view like suggested in above comments.
#foreach($Tasks as $task)
{{ $task->title }}
#endforeach
I have a blade template that I created and I want to add css files depending on the page that it is called to.
The file below is the main file called ._head.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="">
<title>{{ 'Login' }}</title>
<!--Core CSS -->
{{ HTML::style('asset/bs3/css/bootstrap.min.css') }}
{{ HTML::style('asset/css/bootstrap-reset.css') }}
{{ HTML::style('asset/assets/font-awesome/css/font-awesome.css') }}
{{ HTML::style('asset/bs3/css/bootstrap.min.css') }}
<!-- Custom styles for this template -->
#yield('addcss')
<!-- Ends Here -->
{{ HTML::style('asset/css/style.css') }}
{{ HTML::style( 'asset/css/style-responsive.css') }}
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]>{{ HTML::script('asset/js/ie8/ie8-responsive-file-warning.js') }}<![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
I tried to add css to the above template using
#extends('layouts._head')
#section('addcss')
{{ HTML::style('asset/assets/bootstrap-datepicker/css/datepicker.css') }}
{{ HTML::style('asset/assets/bootstrap-daterangepicker/daterangepicker-bs3.css') }}
{{ HTML::style('asset/assets/bootstrap-datetimepicker/css/datetimepicker.css') }}
#stop
#include('layouts._header')
But the contents of the #section and the _head are now showing up inside the body tag after the contents of _header template are displayed. What am I doing wrong here ? Thanks in advance.
You cant "include" something on the same file you "extend" without wrapping it in a section. You should do this:
#extends('layouts._head')
#section('addcss')
{{ HTML::style('asset/assets/bootstrap-datepicker/css/datepicker.css') }}
{{ HTML::style('asset/assets/bootstrap-daterangepicker/daterangepicker-bs3.css') }}
{{ HTML::style('asset/assets/bootstrap-datetimepicker/css/datetimepicker.css') }}
#stop
#section('header')
#include('layouts._header')
#stop
then in your .heads file put the yield of 'header' at the very bottom (or wherever you want it)
....
#yield('header')
</html>
Or if the file remains the same in all views - just do this in .heads
....
#include('layouts._header')
</html>
I'm very new to Laravel and I'm trying to figure out how to use the templating.
I feel so sure that what I have here should work, but I keep getting an error when I run it. I think it has to do with having to #yield commands on the same line. Is this simply a limitation of the blade engine?
routes.php
Route::get('/', function()
{
return View::make('hello');
});
// Test Route:
Route::get('jtest', function(){
$page = array(
"lang" => "en",
"title" => "jtest",
"css" => "css/layout.css",
"rand" => rand()
);
return View::make('jtest')->with('page', $page);
});
jtest.blade.php
#extends('layout')
#section('html-lang')
#if ( isset($page['lang']) )
{{ $page['lang'] }}
#endif
#endsection
#section('title')
#if ( isset($page['title']) )
{{ $page['title'] }}
#endif
#endsection
#section('meta-description')
#if ( isset($page['meta-description']) )
{{ $page['meta-description'] }}
#endif
#endsection
#section('css')
#if ( isset( $page['css'] ) )
{{ $page['css'] }}
#endif
#endsection
#section('rand')
#if ( isset( $page['rand'] ) )
{{ $page['rand'] }}
#endif
#endsection
layout.blade.php
<!doctype html>
<html lang="#yield('html-lang')">
<head>
<meta charset="utf-8">
<title>#yield('title')</title>
<meta name="description" content="#yield('meta-description')">
<meta name="author" content="Jimmy Hogoboom">
<link rel="stylesheet" href="#yield('css')?r=#yield('rand')">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script src=""></script>
</body>
</html>
And the error is
syntax error, unexpected '='
and the line the error's on looks like this:
<link rel="stylesheet" href="<?php echo $__env->yieldContent('css')?r=#yield('rand'); ?>">
So the problem is here:
<link rel="stylesheet" href="#yield('css')?r=#yield('rand')">
If I remove the second #yield:
<link rel="stylesheet" href="#yield('css')?r=">
the page loads fine.
So is this just a limitation of blade, or is there some other way I should be placing these values in the page?
The best idea is to use #yield and sections only for bigger parts like main content or for a sidebar.
If you need 'isset' condition you can use
#if(isset($title)){{$title}}#endif
But this also should be done on controller with clean php including default value for a variable.
I am not sure why you need to use #yield for a small thing.
the following simple code will do the job:
<link rel="stylesheet" href="{{ $page['css'] }}?r={{ $page['rand'] }}">
file: app/route.php
Route::get('/', function()
{
return View::make('home');
});
file: app/views/home.blade.php
{{-- Blade comment. --}}
#extends('layouts.base')
#section('head')
<link rel="stylesheet" href="second.css" />
#stop
#section('body')
<h1>Heading</h1>
<p>Hello Home!</p>
#stop
file: app/views/layouts/base.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
#section('head')
<link rel="stylesheet" href="style.css" />
#show
</head>
<body>
#yield('body')
</body>
</html>
When I access to laravel.localhost/
It only output
#extends('layouts.base')
but however, if I remove the
{{-- Blade comment. --}}
then it works perfectly.
May I know what is the issue?
The first line in your extended blade view must be the #extends directive.
Yes it is a convention by the devs.
Look at BladeCompiler.php on line 119.
protected function compileExtends($value)
{
// By convention, Blade views using template inheritance must begin with the
// #extends expression, otherwise they will not be compiled with template
// inheritance. So, if they do not start with that we will just return.
if (strpos($value, '#extends') !== 0)
{
return $value;
}