Download the PHP package monstrex/voyager-site without Composer
On this page you can find all versions of the php package monstrex/voyager-site. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monstrex/voyager-site
More information about monstrex/voyager-site
Files in monstrex/voyager-site
Package voyager-site
Short Description Voyager Web Site package
License MIT
Homepage https://github.com/monstrex/voyager-site
Informations about the package voyager-site
Voyager Site
The package is an implementation of a simple but useful subsystem of a basic content organization for the Voyager Admin Panel package. Using this package you can rapidly and easily build small and medium-size scale web-sites.
Features
- Basic Page management module, including systems pages.
- Basic SEO implementation - Seo title, Meta Description and Meta Keywords parameters.
- Breadcrumbs implementation.
- Flexible Block / Widget management module, to build parts of your site pages.
- Form management system, including AJAX sending.
- Liquid template subsystem for blocks/widgets and forms.
- Page layout construction using flexible Blocks/Widgets.
- Shortcodes integrated.
- Localizations from DB table, where you can easily keep and manage your translations.
- Advanced site settings module, including mail smtp settings and a mail sending test out of the box.
Installation
Requirement
You should fully install the package Voyager Extension before.
Via Composer
Then run install command:
Publish config if you need:
Usage
Config file
- route_home_page - Route name for Home Page ('home' by default).
- default_model_table - Default model table name to find records ('pages' by default).
- default_slug_field - Default slug field name ('slug' by default).
- use_legacy_error_handler - If false will be used voyager-site 404 error handler.
- template - Root folder name where stored view template files ('template' by default).
- template_master - Master template name ('layouts.master' by default).
- template_layout - Main Layout Template name ('layouts.main' by default).
- template_page - Page template name ('pages.page' by default).
- template_filters - Class to add custom Liquid filters or Null.
Site Settings
Site settings is a flexible and extendable easy to use settings subsystem integrated in the package.
You can use and modify exist settings and group and add you own group and settings. To retrieve certain setting you may use helper function:
Some of the site settings used by the internal package functions will override Laravel .env settings.
The settings have built-in SMTP mail parameters and the mail sending test function.
You can easily modify settings or add new ones using JSON-like setting fields configuration by clicking on the Edit action.
Built-in field types are
- text
- number
- textarea
- rich_text_box (tinyMCE editor)
- code_editor (ACE Code Editor)
- checkbox
- radio
- image (voyager type image)
- media (image file, using laravel medialibrary package)
- route (returns URL using route name)
- section (don't has value, used just for visual separation of field groups)
Localizations
The package provides DB-like localization storage for all strings you need to localize. Just add language columns to the storage and it'll be used instead a localization in files.
Pages
The VPage module allows you manage basic pages on your site. You can easily find and prepare any page and its related attributes - like SEO data, breadcrumbs and data sources and then send this data collection to a view. It can be used by two ways: implementing the PageTrait class into your controller or using the facade VPage. Look for the examples:
Example #1:
Example #2:
What the example does:
- Finds in default (or given) model the certain record (using 'slug' field by default). If you use (int) value then it'll be found by ID field. If a record is not found or the record has empty (null) status field then it'll throw an exception 404.
- Creates a VPage instance and initialize the instance with a Page Data:
- Founded model object.
- Site settings.
- Initialized breadcrumbs.
- Initialized SEO parameters (seo title, meta description, meta keywords).
- Attached data sources, if details field has data sources descriptions.
- Renders page using default (or given) View.
Available variables in the View:
Page Data Sets
It is a subsystem to retrieve additional data necessary to use on a certain page.
The data are different record collections from different models.
To use it you need having details field in your model, the record of that filled up with a certain JSON data structure:
Note: the attached data defined in JSON structure will load automatically during a call the create method.
And in your View template you can easily use it like this:
Note: this type of the JSON data structure also uses in Block/Widget subsystems.
Override default templates on the page
You may want to override default template names on a certain page. To do this define new template names in details field:
Overriding in controllers (using page trait):
Page SEO parameters
SEO parameters are generated inside the create Page method. By default:
SEO Title - from the page seo fields group if an appropriate field is not empty, otherwise checks field Title, if the field is not present then checks a site setting seo.seo_title, if the setting is empty then takes value from site setting general.site_title. And at last the given value passed through seo title template site setting - seo.seo_title_template.
You can override the SEO Title value with method VPage::setSeoTitle('new title').
META Description - from the page seo fields group if an appropriate field is not empty, otherwise checks a site setting seo.meta_description, if the setting is empty then takes value from site setting general.site_description.
You can override the META Description value with method VPage::setMetaDescription('new description').
META Keywords - from the page seo fields group if an appropriate field is not empty, otherwise checks a site setting seo.meta_keywords.
You can override the META Keywords value with method VPage::setMetaKeywords('new keywords').
Page Breadcrumbs
When you call the Page create method it adds the first element to the Breadcrumbs array.
How sets the first breadcrumb element:
To add other elements to the Breadcrumbs array just use the method VPage::addBreadcrumbs($title, $path)
Also you can use the method buildBreadcrumbs() to build a chain of nested pages which hold in the Parents property. This property sets automatically when you load and create page instance using the method setParents($page, $parent_field_name) Where $page is a current page instance and $parent_field_name is a field name where holds ID with a parent of the current page.
Note: additional necessary setup for models - to build parents chain, breadcrumbs and get banner
Blocks / Widgets
Blocks / Widgets is a flexible subsystem provides your a way to implement and organize additional content parts and include them into your page.
Each block has the follow structure:
Status - If disabled the block will be ignored.
Title - Visible only in admin panel.
Block key - A key (slug) using to find and render this block.
Region position - Used for grouping blocks and then render them as a group in certain order. Available positions can be edited in the Regions menu.
Block content - Main block content. You can use as pure HTML code or as a Liquid template.
Available variables:
- this.images - holds images items listed bellow.
- this.field_name - holds additional fields values, where field_name is additional field name in the block table.
- data - Data sources if defined in the Options field.
Example #1 (usage of image list):
Where image.url represent relative URL of image. Crop filter - crop and store (if not stored yet) the image with given sizes. -url filter - makes full url from the relative one. image.full_url - Full url of the image. **image.props.*** - Custom image properties.
Example #2 (usage data sources):
For this kind of template you need to define data sources JSON-like structure in the options field:
Where "model" is a model name equal to registered model name in the Voyager Bread system.
Example #3 (usage internal block's fields):
Also you can get any field of the certain block using helper:
Block render
Just use helper render_block('key'). Instead of key you can use block Title or ID (numeric).
Region (group) render and URL path rules.
It can be used to organize and render a group of blocks whit the same region (group) name whenever you need it in your template. For instance:
Will render all blocks where this region (group) 'content-before' has been set. And the package will check all blocks if they can be rendered - what depends on the setting "URL paths Rules":
It's a drupal-like block system rendering. That can depend on the current URL or not.
Forms
Similar to block. But you can use only limited sets of internal variables. The 'send.form' is implemented inside the form subsystem with the sendForm($request) method. It sends any form data including attached files. Also you can use Google ReCaptcha 2 form protection. Just add the line where you need inside your form:
And add recaptcha validation rules to the form options:
Template part:
Parameters part:
If parameter 'to_address' is not present will be used config setting: mail.to_address.
Inside form template you can use internal vars:
To render form from a view use helper renderForm($key, $subject = null, $suffix = null):
To render inside a block:
More examples:
Also you can use AJAX form sending. The package implements JS part for AJAX sending, just include jQuery library and this line in your view (or you can use your own JS function):
AJAX Example:
Page layout render
The special system allows you to manage group of the blocks or forms and fields on a certain page. You can easily add/remove blocks, forms and fields (and sort them) in the edit page mode and then render using helper:
Where $page is a page instance.
Or manually:
Built-in Shortcodes
block - Render a block. Ex: [block name="top-line"]
form - Render a form. Ex: [form name="top-line" subject="Form subject" suffix="-callback-form"]
div - Render div wrapper. Nested elements not allowed. Ex: [div class="wrapper"] CONTENT [/div]
image - Render html code an image (and crop, convert an image) using media files attached to the current content instance.
Available options:
field - Media file field related with attached media files
index - Index of the file in the collection, begins with 1.
url - Path to the image (if not used field and index)
class - Classes for the image tag. Ex: class="lazy responsive"
lightbox - Make a lightbox wrapper. Ex: lightbox="true"
lightbox_class - Classes for the lightbox wrapper
width - Width attribute fot the image tag.
height - Height attribute fot the image tag.
picture - Add picture wrapper.
crop - Crop the image.
format - Convert the image to webp, jpg, png.
Examples:
[image field="image" index="1"]
[image url="/images/banners/banner-1.jpg"]
[image field="images" index="3" picture="true" format="webp" width="100" height="200" crop="400,400" class="lazy-class" lazy="true" lightbox_class="image-gallery"]
Built-in Liquid filters
url - Return full url for a given path. Ex: {{ '/images/file.jpg' | url }}
route - Return laravel route path. Ex: {{ 'page' | route: 'slug' }}
crop - Crop (and/or convert) image. Ex: {{ this.images[0].url | crop: 300,300,'webp',75 }}
webp - Convert an image into webp format. Ex: {{ this.images[0].url | webp }}
site_setting - Get site settings parameters. Ex: {{ 'mail' | site_setting: 'to_address' }}
menu - Render a menu. Ex: {{ 'main-menu' | menu: 'template.menus.main' }}
block - Render a block. Ex: {{ 'top-line' | block }}
form - Render a form. Ex: {{ 'callback-form' | form: 'Form subject','-callback' }}
trans - Translate string using current locale. Ex: {{ '[[en]]English string[[ru]]Русская строка' | trans }}
lang -- Translate string using language files. Ex: {{ 'auth.password' | lang }}
view -- Render blade view using Data vars. Ex: {{ data | view: 'template.partials.portfolio-list' }}
service -- Get data using service method (and pass it to the View). Ex: {{ 'getPortfolio' | service: '\App\Services\DataService' | view: 'template.partials.portfolio-list' }}
Custom Liquid filters
You can add your own liquid filters using a custom class. You should add this class to the configuration:
'template_filters' => 'App\Template\TemplateFilters'
Helpers
translit_cyrillic($string) - Transliteration given cyrillic string into latin symbols string.
get_file($file_path) - Return URL of the given file_path, can unpack JSON voyager file coded format.
store_post_files(Request $request, $slug, $field, $public = 'public') - Store files given in $request $field and return JSON Voyager array of files links and their original names.
generate_filename($file, $path) - Return new file name if $file exists on given $path.
site_setting($key, $default = null) - Return a site setting (or default value).
site_settings_group($group_key) - Return a group of site settings.
get_image_or_create($image_path, $width, $height, $format, $quality) - Return link to the requested image with a given width and/or height, format and quality. If it not exists it'll be created.
Where:
$image_path - Full URL with domain or relative (to domain).
$width - new image width or Null,
$height - new image height or Null (if used both - width and height - the image will be cropped),
$format - 'webp', 'png', 'jpg': the image will be converted to webp, png, jpg,
$quality - quality level of the new image.
get_first_not_empty(array $values) - Returns the first not empty element in a given array.
render_block($key) - Render block.
render_region($key, $path = null) - Render region (group of blocks with the same region/group key).
render_form($key, $subject = null, $suffix = null) - Render form with a given key. Accept also Subject field and Suffix for using in a form.
render_layout($layout, $page) - Render Page Layout (page group of blocks, forms and page fields).
get_block_field($block_key, $field_name) - Return field value of a given block key.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
- author name
- All Contributors
License
license. Please see the license file for more information.
All versions of voyager-site with dependencies
liquid/liquid Version ^1.4
webwizo/laravel-shortcodes Version ^1.0.20
ext-json Version *