Render
This class provides methods for rendering views, layouts, components, blocks, and managing assets (CSS, JS).
asset()
asset()function asset($assetType, $file, $options = [])$assetType- 'css' or 'js'$file- File name (relative path from the Assets directory in the view)$options- Options array including:'area': (default 'frontend')
'location': (default 'head' or 'footer')
Example:
<?php
Render::asset('css', 'styles.css', ['area' => 'frontend', 'location' => 'head']);
Render::asset('js', 'main.js', ['area' => 'frontend', 'location' => 'footer']);
// Make sure CSS and JS files are contained in Views/Fronted/Assets/ folderrenderAsset()
renderAsset()function renderAsset($location = 'head', $area = 'frontend')$location- 'head' or 'footer'$area- 'frontend' or 'backend'return- Resulting HTML.
Example:
<?php
echo Render::renderAsset('head', 'frontend');
echo Render::renderAsset('footer', 'frontend');render()
render()function render($layout, $view = null, $data = [])$layout- Name of the layout to load (e.g., 'layout' or 'layout2')$view- Name of the view to load (e.g., 'home/home')$data- Data to pass to the viewreturn- The buffered output as a string.
Example:
<?php
$data = ['title' => 'Home Page', 'content' => 'Welcome to the PHPFast Framework!'];
echo Render::render('main', 'home/index', $data);
// Render the main layout with the home/index view, passing the provided data to the view.html()
html()function html($layout, $data = [])$layout- Name of the layout to load (e.g., 'layout' or 'layout2')$data- Data to pass to the viewreturn- The buffered output as a string.
Example:
<?php
$data = ['title' => 'Home Page', 'content' => 'Welcome to the PHPFast Framework!'];
echo Render::html('content', $data);
// Render the main layout, passing the provided data to the layout.component()
component()function component($component, $data = [])$component- Name of the component to render (e.g., 'header', 'footer')$data- Data to pass to the componentreturn- The buffered output as a string.
Example:
<?php
$data = ['title' => 'Home Page'];
echo Render::component('header', $data);
// Render a component named header with some datablock()
block()function block($blockName, $data = [])$blockName- Name of the Block, can be capitalized or lowercase$data- Additional props parameters of the Block, if not provided, Default will be usedreturn- The block instance.
Example:
<?php
$data = ['title' => 'PHPFast', 'description' => 'PHPFast is a fast Framework!!!'];
echo Render::block('head', $data);
// Render a block named head with some datagetblock()
getblock()function getblock($blockName)$blockName- Name of the Block, can be capitalized or lowercasereturn- The block instance or null if the class does not exist.
Example:
<?php
$block = Render::getblock('head');
// Get an instance of a block named exampleLast updated
Was this helpful?