-
Notifications
You must be signed in to change notification settings - Fork 120
Template Component
Jorge Castro edited this page Sep 18, 2020
·
5 revisions
It is a reusable visual object that could be used many times and it could even call itself.
Tag | Description | Example |
---|---|---|
@component/@endcomponent | Call a component. Optionally, it allows to pass arguments |
@component("aaa.bbb",[$a=>1,$b=2]) @endcomponent |
@slot/@endslot | Pass part of the code as a variable | @slot("myslot") --some content-- @endslot |
$slot | It is a special variable | $slot |
You can find the example in
https://github.com/EFTEC/BladeOne/blob/master/examples/testcomponent.php
📄 TestComponent/alert.blade.php
<div class="alert alert-danger" style="background-color: {!! $color !!}; padding-left: 100px;">
<div>{!! $title !!}</div>
{!! $slot !!}
</div>
- $slot is a special variable. It is used to show the content of the caller (excluding every content inside @slot/@endslot)
📄 TestComponent/component.blade.php
You can call the component using the tag @component, and passing the variables as the argument.
@component('TestComponent.alert',array('title'=>'COMPONENT #1','color'=>"red"))
<strong>Whoops!</strong> Something went wrong! (the code is right btw)
@endcomponent
- $slot corresponds to the content: "Whoops! Something went wrong! (the code is right btw)"
📄 TestComponent/component.blade.php
You can also use the tag @slot to pass values to the component.
@component('TestComponent.alert',array('color'=>"red"))
@slot('title')
COMPONENT #1
@endslot
<strong>Whoops!</strong> Something went wrong! (the code is right btw)
@endcomponent
Copyright Jorge Castro Castillo
- BladeOne Manual
- Template tags (views)
- Custom control
- Methods of the class
- Injecting logic before the view (composer)
- Extending the class
- Using BladeOne with YAF Yet Another Framework
- Differences between Blade and BladeOne
- Comparision with Twig (May-2020)
- Changelog
- Changes between 2.x and 3.0 and TODO
- Code Protection (Sourceguardian and similars)