Front End View

In VeltoPHP, the front-end rendering is powered by a lightweight templating engine using the .vel.php file extension. This custom view engine, known as Vel-View, is specifically developed for VeltoPHP and designed to be both intuitive and efficient.

Much like Laravel’s Blade, Vel-View provides a familiar and expressive syntax for embedding dynamic data into HTML. You can output variables using:

# example

{{ $data }}    # Automatically escaped (safe for HTML output)
{!! $data !!}  # Unescaped (raw HTML output)

Directive Replacements

This is the heart of the compiler in your templates and replaces them with equivalent PHP code.


#Layout & Section Control

@extends('layout')        →   Set a layout

@section('content')       →   Start a section
@endsection               →   End a section

@yield('content')         →   Output a section’s content

@include('view')          →   Include another view


# Control Structures

@if(condition)            →   if ()
@elseif(condition)        →   else if ()
@else                     →   else
@endif                    →   end if

@foreach(...)             →   foreach loop
@endforeach               →   end of foreach

@forelse(...)             →   foreach with empty check
@empty                    →   what to show if empty
@endforelse               →   end of forelse

@for(...)                 →   for loop
@endfor                   →   end of for

@while(...)               →   while loop
@endwhile                 →   end of while

@php                      →   open <?php
@endphp                   →   close ?>

# Error Handling

@error('email')           →   Check for validation errors
@enderror                 →   Close error display

# Auth Helpers

@auth                    →   If user is logged in
@endauth

@guest                   →   If user is NOT logged in
@endguest

# CSRF

@csrf                    →   Outputs CSRF token field

# Flash Info

@flash_info(#id)        →   Show specific flash message with spesific ID

# Active Links

@active('dashboard')     →   Outputs `active()` for menu highlighting

# Special Tag Handling

@component('name') → Includes a reusable component.

@role('admin') → Only shows content for users with specific roles.

@end_role → Ends the @role block.

# Echo Output Replacements

{{ $data }}             →   Escaped HTML output using `htmlspecialchars`
{!! $html !!}           →   Unescaped raw HTML

Final Output

Once all replacements are done, the template has been converted into pure PHP, which can be cached and rendered efficiently.

Why This Matters

This compiler allows you to:

  • Write cleaner views using readable syntax
  • Avoid mixing raw PHP in HTML
  • Maintain consistency and security (e.g., auto escaping {{ }})

View Directives Are Still Evolving

VeltoPHP's custom view engine (.vel.php) is a powerful and lightweight solution for building front-end templates. While many directives such as {{ $data }}, {!! $html !!}, @if, @foreach, and layout sections are already functional, the entire directive system is still under active development and refinement.

If you encounter any bugs, unexpected behavior, or missing features in the view system, we welcome your feedback. Please consider:

Your reports and suggestions help us improve VeltoPHP for everyone.

Running on PHP 8.3.20 | VeltoPHP V2.0
Page generated in 10.53 ms

Confirmation

Are you sure?