Skip to content

Commit bc2793a

Browse files
committed
Allow to set the baseUrl to a different folder. Closes #5
1 parent b1503d1 commit bc2793a

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Add illustrations to checkboxes.
1414
- [2. Setup](#2-setup)
1515
* [2.1. Hardcoded options](#21-hardcoded-options)
1616
* [2.2. Dynamic options](#22-dynamic-options)
17-
- [3. Options](#3-options)
18-
- [4. License](#4-license)
17+
- [3. Global options](#3-global-options)
18+
- [4. Per-field options](#4-per-field-options)
19+
- [5. License](#5-license)
1920

2021
<br/>
2122

@@ -84,9 +85,21 @@ I recommend using a `resize` number [already used](https://github.com/k-next/kir
8485

8586
<br/>
8687

87-
## 3. Options
88+
## 3. Global options
8889

89-
#### 3.1. `ratio`
90+
#### 3.1. `baseUrl`
91+
92+
If you want the images to be queried from a different location than the `assets/images` folder, you can set the `baseUrl` option in your `config.php` file to whatever folder you'd like. For example:
93+
94+
```php
95+
'sylvainjule.imageboxes.baseUrl' => '{{ kirby.url("assets") }}/my-custom-folder',
96+
```
97+
98+
<br/>
99+
100+
## 4. Per-field options
101+
102+
#### 4.1. `ratio`
90103

91104
![ratio](https://user-images.githubusercontent.com/14079751/48333927-58bc1880-e659-11e8-8ef2-d239985877ae.jpg)
92105

@@ -98,7 +111,7 @@ myimageboxes:
98111
ratio: 1/1
99112
```
100113

101-
#### 3.2. `fit`
114+
#### 4.2. `fit`
102115

103116
![fit](https://user-images.githubusercontent.com/14079751/48333925-58238200-e659-11e8-811c-074e43b43f2d.jpg)
104117

@@ -110,7 +123,7 @@ myimageboxes:
110123
fit: cover
111124
```
112125

113-
#### 3.3. `mobile`
126+
#### 4.3. `mobile`
114127

115128
By default, images are not displayed when the panel switches to its mobile view. Not recommended, but if you want to override this, set the option to `true`.
116129

@@ -120,7 +133,7 @@ myimageboxes:
120133
mobile: false
121134
```
122135

123-
#### 3.4. `gap`
136+
#### 4.4. `gap`
124137

125138
![gap](https://user-images.githubusercontent.com/14079751/48333926-58bc1880-e659-11e8-8920-6ad913c63529.jpg)
126139

@@ -134,6 +147,6 @@ myimageboxes:
134147

135148
<br/>
136149

137-
## 4. License
150+
## 5. License
138151

139152
MIT

lib/fields/imageboxes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
--------------------------------*/
1313

1414
$base = array_merge_recursive($base, array(
15+
'options' => array(
16+
'baseUrl' => false,
17+
),
1518
'props' => array(
1619
'fit' => function($fit = 'cover') {
1720
return $fit;

lib/options/imageboxes-options.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Kirby\Cms\App;
55

66
class ImageBoxesOptions extends Options {
7+
78
public static function api($api, $model = null): array {
89
$model = $model ?? App::instance()->site();
910
$fetch = null;
@@ -62,15 +63,17 @@ public static function factory($options, array $props = [], $model = null): arra
6263
return [];
6364
}
6465

65-
$assets = kirby()->url('assets') . '/images';
66-
$result = [];
66+
$baseUrl = option('sylvainjule.imageboxes.baseUrl') ?? kirby()->url('assets') . '/images';
67+
$baseUrl = $model->toString($baseUrl);
68+
$baseUrl = rtrim($baseUrl, '/');
69+
$result = [];
6770

6871
foreach ($options as $key => $option) {
6972
if (is_array($option) === false || isset($option['value']) === false) {
7073
$option = [
7174
'value' => is_int($key) ? $option : $key,
7275
'text' => $option['text'],
73-
'image' => $assets . '/' . $option['image'],
76+
'image' => $baseUrl . '/' . $option['image'],
7477
];
7578
}
7679
elseif (is_array($option) === false || isset($option['value']) === true) {

0 commit comments

Comments
 (0)