Support the ongoing development of Laravel.io →
Views Blade Packages
Last updated 2 years ago.
0

That looks cool! Thanks for sharing

Last updated 2 years ago.
0

Very cool, Thanks for sharing!

Last updated 2 years ago.
0

Hi, this is very interesting but i'm confused as to how this package adds value compared to the @Include... You have mentioned that "This functionality can be achieved by using @include, but that can be annoying when your templates are broken down into a ton of tiny templates scattered about." but I don't quite understand this argument.

Would you be kind enough to show a comparison example between @include and this package to show the benefits?

Thanks!

Last updated 2 years ago.
0

I'm coming at it from the angle of trying to create reusable partial templates, like a template for Bootstrap modals or panels.

A good is example is the following: imagine you have a partial template that you want to use to DRY up some of your views, but you have to inject some HTML into it. With @include, it may look something like this:

@include('partials.panel', ['title' => 'This is my panel title','body' => '<div class="row"><div class="col-xs-12">Here is my content</div></div><div class="row"><div class="col-xs-12">It's ugly when I want to print variables, like name: ' . $user->name . '</div></div>'])

Whereas with this package it would look like this:

@partial('partials.panel')
	@block('title', 'This is my panel title')

	@block('body')
		<div class="row">
			<div class="col-xs-12">
				Here is my content
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				It's nicer when you want to echo name: {{ $user->name }}
			</div>
		</div>
	@endblock
@endpartial

@include breaks if it spans more than one line, so you can't even format the array for readability.

Now imagine instead of sending in just simple HTML we wanted to send in a Form using blade syntax... that is going to be a mess when using @include.

Basically what this does is provide template inheritance for partial views. Overall I think it's cleaner and more expressive. Partials are great, but they can be a pain to use as templates that you want to inject content into on the fly.

Hope that helps!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

crhayes crhayes Joined 2 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.