/**
* Include view and display based on a given condition.
*
* @param bool $condition Condition to check.
* @param string $view View name.
* @param array $data View data.
* @param callable|null $callback Callback function used to filter output.
*
* @return void Return void.
*/
public function includeWhen(bool $condition, string $view, array $data = [], ?callable $callback = null): void
Examples
$condition = true;
// Include view.
$view->includeWhen($condition, 'welcome', ['name' => 'Eleven']);
// Include view with callback function used to filter output.
$view->includeWhen($condition, 'welcome', ['name' => 'Eleven'], function ($output) {
// Filter the output end return result
return $output;
});
Getting Started
Methods
- appendSection Start new append section.
- denormalizeName Denormalize view name.
- display Displays the rendered view.
- exists Determining If A View Exists
- extends Extend parent view.
- fetch Fetch view.
- fetchFirst Fetch first view that exists in a given array of views.
- fetchUnless Fetch view based on the negation of a given condition.
- fetchWhen Fetch view based on a given condition.
- getData Share data with all views.
- getFilePath Get view file path.
- getSection Get section.
- getShared Share data with all views.
- hasSection Determine if section exists.
- includeFirst Include view and display.
- includeFirst Include view and display.
- includeUnless Include view and display based on the negation of a given condition.
- includeWhen Include view and display based on a given condition.
- normalizeName Normalize view name.
- prependSection Start new prepend section.
- render Render the view file and extracts the view variables before returning the generated output.
- renderUnless Render the view file and extracts the view variables before returning the generated output based on the negation of a given condition.
- renderWhen Render the view file and extracts the view variables before returning the generated output based on a given condition.
- setDirectory Set views directory.
- setExtension Set views extension.
- share Share data with all views.
- with Share data with all views.