Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Shortcode UI plugin: custom shortcode to access $page

Started by Muut Archive 10 years ago · 3 replies · 1005 views
10 years ago

I'm stuck and I hope someone can help me out.

The challenge is how to access a page's content form within a Shortcode-UI plugin shortcode handler?

For instance suppose I have a shortcode in markdown like:

TXT
[ui-my_custom_shortcode page="my_page_name" /]

Now this is the beginning of the class CalloutShortcode in the file CalloutShortcode.php:

PHP
namespace Grav\Plugin\Shortcodes;

use Thunder\Shortcode\Shortcode\ShortcodeInterface;

class CalloutShortcode extends Shortcode
{
    public function init()
    {
...

From this class I would like to get to the page content of the page which name is used as the page parameter in the shortcode, in this example my_page_name.

I am well aware there are easier and better ways to use another page's content in a page but this is just a simplified example.
Thank you.

10 years ago

Sorry. Sometimes I read too fast. Because you have access to the core Grav object, you can use the Page or Pages API to get to a specific page. But you're going to need the route, not just the page name, methinks.

10 years ago

Thank you! You are right. I'm "unstuck" now. And, oh boy, I still have so much to learn. Which is part of the fun I must add.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 673 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5337 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago