Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Shortcode UI plugin: custom shortcode to access $page

Started by Muut Archive 10 years ago · 3 replies · 705 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 Deleted User, 9 years ago
0 1351 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4062 9 years ago
Archive · by Muut Archive, 9 years ago
1 2948 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago