extendscode / sllize-voyager-themes
此钩子将为Voyager前端主题添加支持
Requires
- larapack/hooks: ~1.0
This package is auto-updated.
Last update: 2024-09-29 23:05:42 UTC
README
Voyager Themes
这是一个为Voyager和钩子系统提供的主题钩子
安装钩子
您可以使用以下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](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_assets
为true或false,如果设置为true,则每次扫描主题目录时,都会将主题中的assets
文件夹发布到新themes
文件夹中的公共文件夹。设置为false则不会发生此操作。
主题选项
您还可以通过在主题文件夹中包含另一个名为options.blade.php
的文件,轻松添加大量选项
在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