andrexm/astatine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

andrexm/astatine

最新稳定版本:v0.1.0

Composer 安装命令:

composer require andrexm/astatine

包简介

A simple PHP template system inspired by Blade.

README 文档

README

A very simple and lightweight PHP template engine with a syntax inspired by Laravel's Blade. It's designed to be easy to use and integrate into your PHP projects without unnecessary complexity.

✨ Features

  • Clean Syntax: Uses @ directives and {{ }} echo statements, familiar to Laravel developers.

  • Template Inheritance: Supports @extends, @section, and @yield for building layouts.

  • Includes: Reuse template partials with the @include directive.

  • Control Structures: Provides convenient directives like @if, @else, @foreach, @while, etc.

  • Echoing Data: Automatically escapes output with {{ $variable }} for security. Use {!! $variable !!} for unescaped data.

  • Lightweight & Fast: Compiles templates into plain PHP code for optimal performance.

🚀 Installation

You can install the package via Composer:

composer require andrexm/astatine

📝 Basic Usage

Here's a quick example of how to use Astatine.

Configuration

First, you need to set up the engine with paths to your template directories.

<?php

require 'vendor/autoload.php';

use Astatine\Engine;

$engine = Engine::getInstance();
$engine::config(
    "views", // Directory for your template files 
    "cache/views", // Directory for your compiled files (must be writable)
    ".php" // OPTIONAL: by default, the engine will look for .blade.php files
);

// Render a template
$engine::render('index', ['name' => 'John Doe']);

See examples/basics.php file. Also, as mentioned in the example above, the engine will look for .blade.php files, in order to allow you to use extensions for syntax highlighting in Blade. If you want to change that, just set the $extension to ".php" (as in the example above) or other stuff.

Also, since you should provide a cache directory, you have to first create that directory:

mkdir -p cache/views

Example Template (templates/index.at.php)

Here is an example to show how similar it is to Blade. Actually, there is a single difference you should be aware of: commands that define blocks must end with a :, like @if(...): ... @endif. Follow the example below to understand better.

{{-- Template Inheritance Example --}}
@extends('layouts.master')

@section('title', 'Home Page')

@section('content'):
    <h1>Hello, {{ $name }}!</h1>

    @if (count($items) > 0):
        <ul>
            @foreach ($items as $item):
                <li>{{ $item }}</li>
            @endforeach
        </ul>
    @else:
        <p>No items found.</p>
    @endif

    @include('partials.footer')
@endsection

Example Layout (templates/layouts/master.at.php)

<!DOCTYPE html>
<html>
<head>
    <title>@yield('title')</title>
</head>
<body>
    <header>
        {{-- Site header --}}
    </header>

    <main>
        @yield('content')
    </main>

    <footer>
        @yield('footer')
    </footer>
</body>
</html>

🧠 Template Syntax Overview

Astatine uses @ prefixed directives and {{ }} for echoed variables.

Control Structures

@if (condition):
    ...
@elseif (condition):
    ...
@else:
    ...
@endif

@foreach ($array as $key => $value):
    ...
@foreach ($array as $value):
    ...
@endforeach

@for ($i = 0; $i < 10; $i++):
    ...
@endfor

@while (condition):
    ...
@endwhile

Template Inheritance

  • @extends('layout.name'): Specifies the layout the template inherits from.

  • @section('name'): ... @endsection: Defines a section block.

  • @yield('name'): In a layout, displays the content of a section.

Including Partials

  • @include('path.to.partial'): Includes another template. Partials always have access to parent data.

Comments

  • {{-- This is a comment --}}: Comments are not rendered in the final HTML.

Echoing Data

  • {{ $variable }}: Echoes escaped data (prevents XSS).

  • {!! $variable !!}: Echoes unescaped data (use carefully!).

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Fork the repository.

  1. Create your feature branch (git checkout -b feature/amazing-feature).

  2. Commit your changes (git commit -m 'Add some amazing feature').

  3. Push to the branch (git push origin feature/amazing-feature).

  4. Open a Pull Request.

📄 License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固