Partials

Props And Defaults

Props pass extra values into a partial when the current context is not enough.

Pass Props#

Pass props on the component tag:

php
<PostCard cta_label="Read more" show_badge="true" />

Inside the partial, read props by name:

phpresources/views/partials/post-card.php
{{ if show_badge }}  <span>Featured</span>{{ /if }}<h2><a href="{{ url }}">{{ title }}</a></h2><span>{{ cta_label }}</span>

cta_label passes text. show_badge="true" passes a boolean-like flag.

Boolean Shorthand#

For boolean flags, you can write the prop without a value:

php
<PostCard cta_label="Read more" show_badge />

Default Props#

A partial can define defaults before a --- separator:

phpresources/views/partials/button.php
label: Read moreurl: /---<a href="{{ url }}">{{ label }}</a>

Caller props override defaults:

php
<Button label="View project" url="/projects/" />