Jump to content

Easy way of creating custom admin pages


diogo
 Share

Recommended Posts

I was thinking of a way of creating custom admin pages without having to create a process module or having to use the $wire object. I came up with a process that is actually very simple (although I think it would be better to create a module for having this functionality). Here is how:

(This will work with the default admin theme, but should also work with other themes)

Go to your /site/templates-admin/default.php (if you don't have it, copy the /wire/templates-admin/ directory to /site/) and change this line

<?php echo $content?>

to this

<?php if($page->template===$templates->admin){echo $content;}else{include($config->paths->templates.$page->template->name.".inc");}?>

Then, go to the /site/templates/ folder and create a file named "custom.php" with this content

<?php include($config->paths->adminTemplates."default.php");

Our setup is ready :)

Now, to create a custom page in the admin:

First, create the new page as child of /Admin/ and point to custom.php as the template file. To do this, when creating the template for the page, go to "ADVANCED" and write "custom" as the "Alternate Template Filename".

Then, instead of creating a TEMPLATE.php file, as you normaly would, create a TEMPLATE.inc file.

You can use all the API variables as you would in a normal template.

Disclaimer: This is a proof of concept, and has still lot's of place for improvement.

edit:

changed from this

if($page->process)

to this

if($page->template === $templates->admin)
  • Like 8
Link to comment
Share on other sites

Looks like a cool technique Diogo! I've created custom admin page for clients to do various things. Usually I'll create a Process module to take care of it. But there have been a couple cases where I just wanted to do it with a template. In those cases, I've had it just use the site's template rather than the admin template, or alternatively just include() the admin template from my own. But will have to try this technique out next time.

Link to comment
Share on other sites

The idea is that you don't have to create a module, I think it's very practical but unfortunately it depends on changing code in the theme, so making a module for this would be more logical.

Link to comment
Share on other sites

  • 3 weeks later...

Hi there,

I've created custom admin page for clients to do various things. Usually I'll create a Process module to take care of it.

I'm trying to create a page like this but I've still not figured how would be the best way to store the data of a custom admin page.

For example, a page with only a email field, how you would setup this? Custom table? I'm using your https://github.com/r...gn/ProcessHello module as base for this.

Sorry for breaking in your thread diogo. :)

Link to comment
Share on other sites

A page - or perhaps do you mean a template? With only an e-mail field?

How about this:

1. Setup > Fields > Create a new field > type: email. Or use the internal email field as an alternative.

2. Setup > Templates > Create a new template > Assign the email field.

Link to comment
Share on other sites

The thing is I was trying to use a Process module for setting up a custom page and I can create a template for it but then I'm unable to link my Process module to it because the process field it's not available for new templates.

Link to comment
Share on other sites

The field 'process' is a system field, so you won't see it in the admin interface as an option to add to a template unless you have $config->advanced=true; in your /site/config.php. You can also add it from the API side. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...