ludmanp / typicms-pageoptions
Allow to add more parameters to a Page in TypiCMS
Requires
- php: ^8.1
- bkwld/croppa: ^7.0
- genealabs/laravel-model-caching: ^12.0
- spatie/laravel-package-tools: ^1.14.0
- spatie/laravel-translatable: ^6.11
- typicms/core: ^13.0
- typicms/nestablecollection: ^5.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: *
- roave/security-advisories: dev-latest
README
Allow to extend TypiCMS Page properties according to page templates.
Installation
You can install the package via composer:
composer require ludmanp/typicms-pageoptions
To prepare for usage you can run
php artisan page-options:install
The command will publish and run the migrations.
You can alternatively run separate commands to do these operations:
php artisan vendor:publish --tag="page-options-migrations"
php artisan migrate
Optionally, you can publish the views using
php artisan vendor:publish --tag="typicms-pageoptions-views"
Usage
Admin
Include
<x-pageoptions-admin-form :model="$model" />
into resources/viwes/vendor/pages/admin/_from.blade.php
.
$model
is the current Page model
Create blade file in resources/viwes/vendor/page-options/admin
directory with page tempalate name.
For example default.blade.php
To add options you can use, for example,
{!! BootForm::text(__('Description'), 'options[description]') !!} {!! TranslatableBootForm::text(__('Phone number'), 'options[phone][number]') !!}
To include specific images, use
<x-pageoptions-image :model="$model" name="preview_image_id" label="Preview image"/> <x-pageoptions-image :model="$model" name="phone.icon_id" label="Phone icon"/>
name
is option's name, use dots to make multilevel array.
label
is optional, but recommended to distinguish from other image fields
The same way you can add file fields
<x-pageoptions-file :model="$model" name="specification" label="Specification"/>
Public
To output PageOptions use in page template (pages/public/*.blade/php
)
To output simple option use
{{ $pageOptions->present()->option('phone') }}
To output translatable option use
{{ $pageOptions->present()->optionTranslated('company.name') }}
There is available optional locale parameter
{{ $pageOptions->present()->optionTranslated('company.name', 'en') }}
To output image use
<img src="{{ $pageOptions->present()->optionsImage('contact.image') }}" alt="{{ optional($pageOptions->present()->optionsFile('contact.image'))->alt_attribute ?? 'Contacts' }}"/>
Additional parameters width
, height
and options
are available, like in presenter's image
method.
To get file model use.
$pageOptions->present()->optionsFile('contact.file')
As you can see above it is available also for images to get alt_attribute
for example.
To make link to file you can write like following
<a href="{{ optional($pageOptions->present()->optionsFile('contact.file'))->url }}">File</a>
Credits
License
The MIT License (MIT). Please see License File for more information.