Skip to content

Commit be1b12e

Browse files
committed
some fixes
1 parent b38fefd commit be1b12e

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
# v5.2.0
2+
## 06/02/2024
3+
4+
1. [](#new)
5+
* Added the ability to display a section from another page. See README.txt for example
6+
1. [](#bugfix)
7+
* Fix for `lorem` shortcode that broke when count was provided
8+
9+
110
# v5.1.3
211
## 06/01/2022
312

413
1. [](#improved)
514
* Added a new `display` CLI command to show all registered shortcodes
615

16+
717
# v5.1.2
818
## 05/10/2022
919

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,20 @@ This we be removed from the page content and made available in Twig variables so
284284
285285
#### Sections from other pages
286286
287-
You can even retrieve a section from another page utilizing the shortcodes as they are stored in the page's `contentMeta` with this syntax:
287+
You can even retrieve a section from another page utilizing the shortcodes as they are stored in the page's `contentMeta` with this Twig syntax:
288288
289289
```
290290
<div id="author">{{ page.find('/my/custom/page').contentMeta.shortcodeMeta.shortcode.section.author }}</div>
291291
```
292292
293+
There may be a scenario where you define a section in another page, but want to use it in the content of a page. You can now do so with the same `[section]` shortcode by providing the page where the section is defined, and also the name of the section with no shortcode body. For example
294+
295+
```markdown
296+
[section page="/my/custom/page" name="author" /]
297+
```
298+
299+
!! NOTE for this to work, the shortcode needs to be defined a parent page, or page that has been processed before the current page.
300+
293301
#### Notice
294302

295303
A useful shortcode that performs a similar job to the [markdown-notices](https://github.com/getgrav/grav-plugin-markdown-notices) plugins, allows you to easily create simple notice blocks as seen on http://learn.getgrav.org and http://getgrav.org. To use simply use the following syntax:

classes/shortcodes/LoremShortcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function words($count = 1, $tags = false, $array = false)
145145
}
146146
}
147147
}
148-
$words = array_slice($words, 0, $count);
148+
$words = array_slice($words, 0, (int) $count);
149149

150150
return $this->output($words, $tags, $array);
151151
}

classes/shortcodes/SectionShortcode.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ public function init()
99
{
1010
$this->shortcode->getHandlers()->add('section', function(ShortcodeInterface $sc) {
1111
$name = $sc->getParameter('name');
12+
$page = $sc->getParameter('page');
13+
$content = $sc->getContent();
14+
15+
if (empty($content) && isset($page)) {
16+
if ($target = $this->grav['pages']->find($page)) {
17+
if ($shortcodeObject = $target->contentMeta()['shortcodeMeta']['shortcode'][$sc->getName()][$name] ?? false) {
18+
return (string) $shortcodeObject;
19+
}
20+
}
21+
}
22+
1223
$object = new \Grav\Plugin\ShortcodeCore\ShortcodeObject($name, $sc->getContent());
1324
$this->shortcode->addObject($sc->getName(), $object);
1425
});

0 commit comments

Comments
 (0)