Skip to content

Commit

Permalink
Options, assets
Browse files Browse the repository at this point in the history
  • Loading branch information
OleVik committed Dec 25, 2019
1 parent 5c3a8ae commit 3ffddcf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.0.1
## 25-12-2019

1. [](#new)
* CSS- and JS-options
2. [](#improve)
* Asset-loading

# v1.0.0
## 21-12-2019

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The plugin exposes a `[slider]`-shortcode, a Page Type and a template-partial. T
- Options are set with the dot-notation format
- Options with no explicit value are interpreted as `true`
- Slides can contain any content that Swiper accepts, and each Slide within `[slider]` and `[/slider]` must be separated by a new line
- Assets are loaded with either of the plugin's templates, and added to Grav's assets
- Assets are loaded by default
- Default settings can be set with the `defaults` in `/user/config/plugins/swiper.yaml`

### Example
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Swiper
version: 1.0.0
version: 1.0.1
description: Swiper for Grav CMS
icon: plug
author:
Expand Down
13 changes: 12 additions & 1 deletion swiper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function onPluginsInitialized()
$this->enable(
[
'onShortcodeHandlers' => ['shortcodes', 0],
'onTwigTemplatePaths' => ['templates', 0]
'onTwigTemplatePaths' => ['templates', 0],
'onAssetsInitialized' => ['assets', 0]
]
);
}
Expand Down Expand Up @@ -84,4 +85,14 @@ public function shortcodes()
$this->grav['shortcode']->registerAllShortcodes(__DIR__ . '/shortcodes');
}
}

public function assets()
{
if ($this->config->get('plugins.swiper.css')) {
$this->grav['assets']->addCss('plugins://swiper/node_modules/swiper/css/swiper.min.css');
}
if ($this->config->get('plugins.swiper.js')) {
$this->grav['assets']->addJs('plugins://swiper/node_modules/swiper/js/swiper.min.js');
}
}
}
2 changes: 2 additions & 0 deletions swiper.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
enabled: true
css: true
js: true
templates: true
shortcodes: true
defaults:
Expand Down
3 changes: 0 additions & 3 deletions templates/partials/slider.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{% do assets.addCss('plugins://swiper/node_modules/swiper/css/swiper.min.css', 100) %}
{% do assets.addJs('plugins://swiper/node_modules/swiper/js/swiper.min.js', 100) %}

<div id="{{ id }}" class="swiper-container">
<div class="swiper-wrapper">
{{ content }}
Expand Down
5 changes: 1 addition & 4 deletions templates/slider.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
{% extends page.parent.template ~ '.html.twig' %}

{% do assets.addCss('plugins://swiper/node_modules/swiper/css/swiper.min.css', 100) %}
{% do assets.addJs('plugins://swiper/node_modules/swiper/js/swiper.min.js', 100) %}
{% extends page.parent.template ~ '.html.twig' %}

0 comments on commit 3ffddcf

Please sign in to comment.