Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add page handler #213

Closed
StephanStanisic opened this issue Aug 7, 2020 · 1 comment
Closed

[Feature request] Add page handler #213

StephanStanisic opened this issue Aug 7, 2020 · 1 comment

Comments

@StephanStanisic
Copy link

StephanStanisic commented Aug 7, 2020

Something that I find lacking is the ability to add custom pages from plugins. Currently a plugin like the blog plugin and store plugin use a rather complex and convoluted way to create custom pages. My suggestion would be to incorporate into core, in order to make this usable.

Example usage of this:

<?php
global $Wcms;

// @param slug: string
// @param page_callback: callable
$Wcms->registerPage("blog", function($args){
    return [
        "title" => "My Blog",
        "description" => "Some description",
        "keywords" => "a, few, keywords",
        "content" => "Hello, world! " . json_encode($args)
    ];
});

Core could execute the function in argument 2 to get all information to construct a page. This would trigger as follows:

url /blog would call function with [] as argument
url /blog/foo would call function with ["foo"] as argument
url /blog/foo/bar/baz would call function with ["foo", "bar", "baz"] as argument

@robiso robiso changed the title [feature-request] Add page handler [Feature request] Add page handler Aug 11, 2020
@robiso robiso pinned this issue Oct 14, 2020
@robiso robiso unpinned this issue Jan 1, 2022
@robiso robiso pinned this issue Jan 29, 2022
@robiso
Copy link
Collaborator

robiso commented May 15, 2022

Hey @StephanStanisic, hope you're doing good.

With the latest version of WonderCMS, you can do this by using:
$Wcms->createPage('blog/foo', true);
$Wcms->updatePage('blog/foo', 'title', 'Lorem ipsum');

Example from the code in index.php where it's used:

	/**
	 * Update page data
	 *
	 * @param array $slugTree
	 * @param string $fieldname
	 * @param string $content
	 * @return void
	 * @throws Exception
	 */

$Wcms->updatePage($this->currentPageTree, $fieldname, $content);

In retrospect, this seems to achieve the same result:

$Wcms->registerPage("blog", function($args){
    return [
        "title" => "My Blog",
        "description" => "Some description",
        "keywords" => "a, few, keywords",
        "content" => "Hello, world! " . json_encode($args)
    ];
});
// Should be the same as.
$Wcms->createPage('blog', true);
$Wcms->updatePage('blog', 'title', 'My Blog');
$Wcms->updatePage('blog', 'description', 'Some description');
$Wcms->updatePage('blog', 'keywords', 'a, few, keywords');
$Wcms->updatePage('blog', 'content', "Hello, world! " . json_encode($args));

Please reopen the issue if this isn't approximately what you meant.

@robiso robiso closed this as completed May 15, 2022
@robiso robiso unpinned this issue May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants