hongyukeji/laravel-theme

v2.1.0 2020-08-11 14:26 UTC

This package is auto-updated.

Last update: 2024-04-11 22:09:34 UTC


README

Laravel 主题模板功能, 这可能是我用过最优雅的laravel主题扩展

Installing

$ composer require hongyukeji/laravel-theme
$ php artisan vendor:publish --provider="Hongyukeji\LaravelTheme\ThemeServiceProvider"

Usage

特点

利用 View::addNamespace() 和 View::prependNamespace() 实现主题模板功能

使用

// 1. 在 config/themes.php 中 添加 templates, 如:
'templates' => [
    'frontend' => [
        'path' => 'frontend',
        'template' => 'default',
        'default' => 'default',
    ],
],

// 2. 在控制器中使用:
public function index()
{
    return view('frontend::index.index');
}

// 3. 在视图目录新建frontend目录和对应的index(frontend => 终端, default => 主题):
resources/views/frontend
resources/views/frontend/default
resources/views/frontend/default/index
resources/views/frontend/default/index/index.blade.php

templates 配置说明

  • path 为每个终端模板目录路径
  • template 为使用模板的目录
  • default 为默认模板目录, 即找不到template模板对应的目录文件, 会自动在该参数定义的目录去查找

助手函数你可能会需要

  • get_template_dir 获取给定路径下的所有目录

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT