Skip to content

Commit

Permalink
Add default gallery template (#2)
Browse files Browse the repository at this point in the history
* Add default gallery template
* Bump up the version
  • Loading branch information
Karmalakas authored Jun 21, 2021
1 parent b6b2f35 commit e98ead1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.1.0
## 21-06-2021

1. [](#new)
* Add default template

# v1.0.1
## 14-03-2021

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Photoswipe
slug: photoswipe
type: plugin
version: 1.0.1
version: 1.1.0
description: Add Photoswipe gallery to your pages
icon: image
author:
Expand Down
17 changes: 17 additions & 0 deletions photoswipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Plugin;
use Grav\Common\Twig\Twig;
use Grav\Plugin\Photoswipe\Twig\PhotoswipeExtension;
use RocketTheme\Toolbox\Event\Event;

/**
* Class PhotoswipePlugin
Expand Down Expand Up @@ -51,6 +53,12 @@ public function autoload(): ClassLoader
public function onPluginsInitialized(): void
{
if ($this->isAdmin()) {
$this->enable(
[
'onGetPageTemplates' => ['onGetPageTemplates', 0],
]
);

return;
}

Expand All @@ -63,6 +71,15 @@ public function onPluginsInitialized(): void
);
}

/**
* Add blueprint directory to page templates.
*/
public function onGetPageTemplates(Event $event)
{
$locator = Grav::instance()['locator'];
$event->types->scanTemplates($locator->findResource('plugin://' . $this->name . '/templates'));
}

/**
* Register templates
*
Expand Down
17 changes: 17 additions & 0 deletions templates/photoswipe.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'default.html.twig' %}

{% block content %}
{{ parent() }}

{% set item_id = 'photoswipe-gallery-' ~ random() %}

{{ photoswipe(item_id, 'a') }}

<div id="{{ item_id }}">
{% for item in page.media.images %}
<a href="{{ item.url|e }}" class="gallery-item" data-size="{{ item.width ~ 'x' ~ item.height }}">
<img src="{{ item.cropResize(500, 250).url|e }}" alt=""/>
</a>
{% endfor %}
</div>
{% endblock %}

0 comments on commit e98ead1

Please sign in to comment.