I'm new to Laravel 4. I don't seem to find adequate documentation on the Blade templating system.
I see some examples at http://laravel.com/docs/templates with no explanation.
Another example at Laravel 4 Controller Templating / Blade - Correct method?
Where are #section, #yield, #show, etc defined and documented? Where is the Blade templating system actually explained?
Or is it so new, or so "intuitive", that it needs no explanation? Or I could use another templating system that is better documented?
I would say Blade is so easy that it doesn’t need documentation.
Follow this link great tutorial by Jeffrey Way which will take you through everything you need to know.
https://tutsplus.com/lesson/templating-changes/
I am totally convinced that the original documentation about has many areas of opportunity. Anyway, Dayle Rees has done an excellent job through the pages of Code Bright. The Blade section of the book has some great examples that perfectly complement the original documentation. I find it strange that wasn't previously mentioned. You should give it a look.
Regards!
The documentation for Blade isn't in the laravel.com docs. No, they tucked it away in their readthedocs.io account:
https://laravel-guide.readthedocs.io/en/latest/blade/
Related
I know that naming conventions in Laravel is covered in another question, but blade files are not covered there. I read several blogs and forums and they all offer different approach so I want to ask here:
My controller method is AdminController#listPropertyTypes - which lists and manages the property types..
One blog suggests:
/resources/views/admin/property/types.blade.php
Another blogs suggest underscore or no space:
/resources/views/admin/property_types.blade.php
/resources/views/admin/propertytypes.blade.php
I would personally named this way since it is a view:
/resources/views/admin/property-types.blade.php
Is there a best practice or PSR rule for this?
EDIT: Laravel community mostly use kebab-case or camelCase
ie views/admin/property-types.blade.php or views/admin/propertyTypes.blade.php
Laravel's creator seems to use kebab-case, but Spatie recommends camelCase.
As #MrEduar explained it, there is no strict convention.
NB: https://www.laravelbestpractices.com website is abandonned and not affiliated with Laravel.
OLD: Initial answer
I came across Laravel Best Practices.
Laravel : Best Practices aims to put together all the resources and best practices in using the Laravel Framework. Last Updated: 2020-05-07 12:26:48
Views
You SHOULD use snake_case as file name of your Blade templates
Good
show_filtered.blade.php
Bad
showFiltered.blade.php
show-filtered.blade.php
For blade file names, there is no convention as such. But as #James says in his commentary, and I quote
If you are asking about best practices, then one suggestion would be
to strictly use CRUD controllers; AdminController#listPropertyTypes is
not CRUD. AdminPropertyTypesController#index is more "best practice".
And in this case the best way would be /resources/views/admin/property/types.blade.php.
You can read more about this in Laracon 2017 or in Adam Watham's github repository where he explains it further.
If you are not happy with this result I suggest you also use CamelCase According to the Spatie Guidelines
resources/
views/
openSource.blade.php
So, in the controller
class OpenSourceController
{
public function index() {
return view('openSource');
}
}
Instead of looking at unreliable blogs, be guided by the great minds of the Laravel community.
Looking at the laravel blade source code, I see there appear to be a lot of different commands, like #show, #append, or #endunless, that don't appear in the official laravel docs. Can someone give me a list of all the #- options in blade, and what they do?
You could try digging around in the online API docs and see if that yields the answers you're looking for. Possibly some of them are internal methods?
Illuminate\View\Compilers\BladeCompiler
I'm currently starting a project on the beta version of Laravel 4
When i try to use the templating engine some tags work and some doesn't. e.g:
#layout('layouts.master')
#section('container')
<h1>About US</h1>
#endsection
is displayed as:
#layout('layouts.master')
About US
#endsection
which means that the #section tag is parsed, but the other are referred to as plain text.
also if i change the #layout to #include, it does include the template.
Has anyone run into a similar issue? Have there been any syntax changes I'm unaware of?
#layout has been changed to #extends in Laravel 4. Also, #endsection has been changed to #stop
The source of the problem is that a lot of tutorials online (youtube and blogs) still use the #layout and #endsection. And these tutorials usually claim to be Laravel4 tutorials as well.
So a lot of people fall in to this little trap starting their first Laravel4 app.
Tip: I use this guy's cheat sheet page while developing (propers to Jesse O'Brien). It's how I found out myself I was using outdated blade tags.
If you come across problems with Laravel or in case you don't know if Laravel has built in a functionality you'd need, allways check out the docs for the Laravel version you use.
The online documentation of the current released version (4 at the time of writing): http://laravel.com/docs/
and the Laravel API to dive into the source online with explanation of e.g. function arguments: http://laravel.com/api/
I'm trying to use Phil Sturgeon's CodeIgniter Template library, but I can't get it to change my pages. I read the documentation, followed the steps there,
Download
Copy to application folder
Create a views/layouts/default view
(Auto)load the library
however, it is not clear as to how the template is actually implemented. I thought that loading the view would apply the template everywhere, but it doesn't seem to work that way. I've also read about it in the CodeIgniter Wiki, but it looked too complicated to be the right answer.
How are you supposed to use Phil Sturgeon's Template with your controllers? (or views?) Am I missing something here?
It does not overload the load->view() methods, that would be bad. You need to update your controllers to use the template's syntax and methods in every instance you want to use it:
http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/
You will use $this->template->build() instead of $this->load->view() in most cases, after constructing your template by defining regions, setting titles, etc.
There should have been a user guide included in your download with examples.
I am trying to build an autosuggest using CodeIgniter, can i have some examples?
Try their video tutorials. They show you how to make a blog and a basic introduction to CodeIgniter.
Also, they have another list of tutorials that might give you a better idea.
Have a look at the PHP form_helper that shows you how to add javascript events and PHP callbacks on to form elements both of these you will need to use to work.
Good Luck