gondwe/voyager-themes

该包最新版本(0.16.3)没有可用的许可证信息。

此钩子将添加对Voyager前端主题的支持

0.16.3 2022-08-14 00:39 UTC

This package is auto-updated.

Last update: 2024-09-14 04:58:54 UTC


README

Voyager Themes

这是一个Voyager和钩子系统的主题钩子

Voyager Themes Admin Page

安装钩子

您可以使用以下Artisan命令来安装此钩子

php artisan hook:install voyager-themes

添加主题

voyager-themes钩子将查找resources/themes文件夹中的任何包含同名.json文件的文件夹。(您可以在配置中更改主题文件夹的位置)

例如,如果您有一个名为sample-theme的文件夹,在该文件夹中还有一个名为sample-theme.json的文件,其内容如下

{
    "name": "Sample Theme",
    "version": "1.0"
}

Voyager Themes将检测这是一个新主题。您还可以包含一个主题的示例截图,该截图为sample-theme.jpg (最佳结果为800x500像素)

实际上,您可以在以下位置查看sample-theme存储库:https://github.com/thedevdojo/sample-theme

您可以在Voyager中激活此主题,然后当您想告诉应用程序要加载哪个视图时,可以使用

return view('theme::welcome')

然后它将在当前活动主题文件夹中查找名为welcome.blade.php的新视图:D

主题配置

您可以通过运行以下命令将配置发布到项目中

php artisan vendor:publish

您将需要发布voyager-themes-config,现在您将看到一个新配置位于config/themes.php中,如下所示

<?php

return [

    'themes_folder' => resource_path('views/themes'),
    'publish_assets' => true

];

现在,您可以选择将主题文件夹放在其他位置。默认情况下,它将放在resources/views文件夹中;但是,您可以将其更改为任何您想要的位置。

此外,您可以设置publish_assetstruefalse,如果设置为true,则每次扫描主题目录时,它将发布主题中的assets文件夹到名为themes的新公共文件夹中。将其设置为false,则不会发生此操作。

主题选项

您还可以通过在主题文件夹中包含另一个名为options.blade.php的文件,轻松添加多个选项

Voyager Theme Options Page

options.blade.php文件中,您现在可以添加一个新字段,就像这样

{!! theme_field('text', 'title') !!}

这将现在添加一个新的文本字段,并使用一个title)存储它。因此,现在如果您想在任何主题文件中引用此值,您可以简单地按如下方式输出它

{{ theme('title') }}

不是很容易吗,对吧!

查看以下对theme_field函数的所有以下解释。

theme_field函数

theme_field()函数可以用来在我们的主题选项页面显示字段。请查看以下函数的定义示例说明字段类型

定义

theme_field(
    $type, 
    $key,
    $title = '',
    $content = '', 
    $details = '', 
    $placeholder = '', 
    $required = 1)

示例:请求标题的文本框

{!! theme_field(
        'text', 
        'headline', 
        'My Aweseome Headline', 
        '{}', 
        'Add your Headline here', 
        0) 
 !!}

只有前两个参数是必需的

{!! theme_field('text', 'headline') !!}

说明

$type
    This is the type of field you want to display, you can
    take a look at all the fields from the TYPES OF FIELDS
    section below.
 $key
    This is the key you want to create to reference the
    field in your theme.
 $title
    This is the title or the label above the field
  $content 
    The current contents or value of the field, if the field
    has already been created in the db, the value in the
    database will be used instead
  $details
    The details of the field in JSON. You can find more 
    info about the details from the following URL:
    https://voyager.readme.io/docs/additional-field-options
  $placeholder
    The placeholder value of the field
  $required
    Whether or not this field is required

字段类型

checkbox, color, date, file, image, multiple_images,
number, password, radio_btn, rich_text_box, code_editor,
markdown_editor, select_dropdown, select_multiple, text,
text_area, timestamp, hidden, coordinates