Using variables | laravel-blade-x | Spatie

 SPATIE

laravel-blade-x
===============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-blade-x](https://spatie.be/docs/laravel-blade-x/v2)  Basic-usage  Using variables

 Version   v2

 Other versions for crawler [v2](https://spatie.be/docs/laravel-blade-x/v2)

  Using variables
- [ Introduction ](https://spatie.be/docs/laravel-blade-x/v2/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-blade-x/v2/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-blade-x/v2/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-blade-x/v2/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-blade-x/v2/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-blade-x/v2/changelog)
- [ Upgrading ](https://spatie.be/docs/laravel-blade-x/v2/upgrading)
- [ About us ](https://spatie.be/docs/laravel-blade-x/v2/about-us)

Basic usage
-----------

- [ Writing your first component ](https://spatie.be/docs/laravel-blade-x/v2/basic-usage/writing-your-first-component)
- [ Using variables ](https://spatie.be/docs/laravel-blade-x/v2/basic-usage/using-variables)
- [ Using slots ](https://spatie.be/docs/laravel-blade-x/v2/basic-usage/using-slots)

Advanced usage
--------------

- [ Transforming data with view models ](https://spatie.be/docs/laravel-blade-x/v2/advanced-usage/transforming-data-with-view-models)
- [ Sharing data with context ](https://spatie.be/docs/laravel-blade-x/v2/advanced-usage/sharing-data-with-context)
- [ Prefixing components ](https://spatie.be/docs/laravel-blade-x/v2/advanced-usage/prefixing-components)

Under the hood
--------------

- [ From BladeX to Blade ](https://spatie.be/docs/laravel-blade-x/v2/under-the-hood/from-bladex-to-blade)

 Using variables
===============

###  On this page

1. [ Spread operator for attributes ](#content-spread-operator-for-attributes)
2. [ Boolean attributes ](#content-boolean-attributes)

When using a BladeX component all attributes will be passed as variables to the underlying Blade view.

```
{{-- the `myAlert` view will receive a variable named `type` with a value of `error` --}}

```

If you want to pass on a PHP variable or something that needs to be evaluated you must prefix the attribute name with `:`.

```
{{-- the `myAlert` view will receive the contents of `$message` --}}

{{-- the `myAlert` view will receive the uppercased contents of `$message` --}}

```

Spread operator for attributes
--------------------------------------------------------------------------------------------------------------------------------------------------

Passing an array of component attributes to a BladeX component can be achieved using the spread operator:

```

```

Combining multiple destructured arrays and normal attributes is supported too! Normal attributes will override attributes in the spreaded attributes array.

```

```

Boolean attributes
--------------------------------------------------------------------------------------------------------------

Boolean attributes (attributes without a value), e.g. `` will be passed to the component as variables evaluating to `true`.

```
{{-- the `checkboxInput` view will receive a `$checked` variable that evaluates as true --}}

```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
