I am building a website and I'm creating an admin and user login form but I'm facing some problems because when I try to type for example #extends or any other function with # it doest change color or do anything (sorry for not being to clear). So basically it doesn't act as a function but just as a simple text that later shows up at the display on the website. If anyone can help me i would be very happy because I have been trying for hours and its important for me to finish this website
Image of code in my editor where the color is not changing
Image of code that isn't working correctly
adminLoginController
This is what i get on localhost
This is what i did trying to add layout
The lack of color highlighting is "syntax highlighting". Your editor would need support for Blade to be able to highlight the Blade syntax correctly.
The Blade directive #extends needs to take an argument/expression:
#extends('layouts.app')
"When defining a child view, use the Blade #extends directive to specify which layout the child view should "inherit".
Laravel 6.x Docs - Blade - Extending a Layout #extends()
When it comes to rendering these templates, just make sure the file ends with .blade.php if you want it to be a Blade template.
"Blade view files use the .blade.php file extension and are typically stored in the resources/views directory."
Laravel 6.x Docs - Blade - Introduction
Update:
You do not have a layouts directory in resources/views. You need to extend an existing layout. By the looks of your structure you mean to extend auth.layouts.app:
#extends('auth.layouts.app')
Also you are not defining a #section('content') to be #yielded in the layout.
#extends('what.ever.layout.you.want.to.use')
#section('content)
<!-- your content here -->
#endsection
Please make sure your blade file filenames are in the format of:
my_custom_file.blade.php
And not just:
my_custom_file.php
If you just end your files in .php then Laravel will not process it as a Blade template. The #extends directive is a Blade template feature and will need to be pre-processed into regular PHP by Laravel for it to work. It does this automatically when you use the return view('my_custom_view') syntax. This line would look for a file in resources/views/my_custom_view.blade.php first.
From your file structure layouts.blade.php is located in your views directory, so what you need to do is:
#extends('layouts')
To extend the layouts.blade.php
Related
I'm wanting to create a website with laravel framework. I had made layout but now, have some zone i don't know how to set content for it. Ex: 2 zone of me are left-menu and cart (please view picture). My left-menu will get content from table: categories and cart will get content from package cart [Cart::content()].
It's on layout and of course, all page will have it. But i don't know how to give content of categories and cart() for it. Please help me
I think that you should to use View Composer.
https://laravel.com/docs/5.6/views#view-composers
Use Blade templates, as found here: https://laravel.com/docs/5.6/blade
Wherever in your page you want to print content, use the {{ $mycontent }} construct. You can also use confitionals and loop structures like #if and #foreach to loop through collections.
Then, in your controllers, you can just call the view and pass it content from your database or wherever you get it by doing something like:
return response()->view(“myView”, [“mycontent” => $content], $httpStatus);
You may opt for afterMiddleware if you want it on every page. Create a section on the master blade page (usually app.blade.php) and fill it in the middleware just like you would in any other controller. You can create a middleware by running php artisan create:middleware Cart. A file will be created at app/Http/Middleware/Cart.php.
Register the middleware in the app/Http/kernel.php file.
You may have to add a Auth::check() condition to avoid errors.
A started to work with Phalcon framework, included Blade templating. It's already works, but unfortunately i didn't find the right way to include css and JS assets in master.blade.php.
If I add the assets like $this->assets->addCss("css/bootstrap.min.css"); in the controller I can not include it in the master template file.
For example, my indexAction looks like this:
public function indexAction(){
$this->assets->addCss("css/bootstrap.min.css");
$this->assets->addJs("js/bootstrap.min.js");
return $this->blade->make('index.index');
}
Thanks for any help!
Well - you should add blade as actual template engine into phalcon view.
Your class should extends Engine implements EngineInterface. If you will do it it could be nice to add it to incubator repository.
https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Mvc/View/Engine check out implementation of other engines for more how are they made. Then you could just do {{ assets.outputJss() }}, example from volt/twig, not sure how exactly it should look like in blade, never used it.
Also what's wrong with volt? It's faster than blade and have many features.
My app.blade.php file is my main file that will #yield all my other blade template files. I noticed that the Auth class is available to this file. I cant figure out how to add one of my custom classes, Projects so it is available to app.blade.php.
app.blade.php contains a drop down menu where I need to list all my projects, but if I try something like
Projects::where('user_id','=',Auth::user()->id)->get()
I get an error saying the Projects class is not found. How can I add this to my master template just like how Auth is available? Or, do I need to go about this differently?
You do it by injecting the class into your template.
#inject('project', 'App\Project')
{{ $project->where('user_id','=',Auth::user()->id)->get() }}
Just make sure your namespace is correct.
http://laravel.com/docs/5.1/blade#service-injection
I want to change the Gii template follow my own template that I have where I found the code to change
<div class="errorMessage">....</div> become my own template style??
I have changed most of the gii templates style follow mine but i have not found the line to change the "div" error message on : framework\gii\generators\crud\templates\default
The main view file for CRUD generation is in framework\gii\generators\crud\templates\views\index.php. The form is generated using CCodeForm, and the error messages are generated using the $form->error() method.
You can customise these considerably by just passsing parameters to the $form->error() method as described here, or you can override the $form->error() method by creating your own class which extends CCodeForm, but that may have unintended results!
I'd suggest, for ease, that you pass parameters to each of the $form->error() methods that are called in the view file.
To do this, follow these steps;
Create a folder 'gii' in your protected folder
Create a folder within that called 'crud'
Into that folder copy the entire contents of `framework/gii/generators/crud. These files will now override the default files from gii.
Open protected/gii/crud/views/index.php
Find all the error fields. They look like <?php echo $form->error($model,'controller'); ?>
Add an array of html options to the error declaration, so it looks like <?php echo $form->error($model,'controller', array('class' => 'alert alert-error')); ?>
Thats it! This method has the benefit that you haven't modified the core framework files, so if you update yii your changes will not be overwritten. For more information, have a look at this http://www.yiiframework.com/doc/guide/1.1/en/topics.gii
I am trying to insert a latest tweets "widget" on to a Symfony2 project. I have found an ideal script written in PHP that will do the job perfectly.
However, I don't know where the best place to put 3rd party PHP files in a Symfony2 project. I have placed them in the same folder as all my twig files reside, changed the name to read tweets.php.twig, and even located them in the web folder. When I try to include the file in the twig file that needs the Twitter feed it comes up with an error saying that it can't find the file.
Do I have the right idea, or do I have to convert the PHP in to a twig file or write the PHP script in to a controller?
I believe the recommended way would be to create a Symfony2 bundle that encapsulates all the logic for the tweet widget. You would then call your bundle controller and pass the response to your twig template.
If that is too complicated or you want something more quick and dirty - you can create a controller like TweetWidgetController.php and put the code into there as an action like widgetAction. Just make sure you return the tweet widget output in a Symfony response object.
Then from your main controller - you can do something like
$widget = $this->forward('YourBundle:TweetWidget:widget', array('twitterid' => 'yourtwitterid'));
return $this->render('YourBundle:yourtemplate.html.twig',array('widget' => $widget->getContent()));
Now in your twig template you can put it wherever you'd like by referencing it as:
{{ widget }}