Jump to content
madalin

How to create a custom admin settings page?

Recommended Posts

Hello there!

I'm new to Processwire (like almost 2 days from my first look at the code and admin interface) but i am already in love with it!

Well... how much i already love the ideea, i can't manage to create a page under the admin page to show as tab with some functionality. (actually the page is created but i don't know how to add the functionality i want)

I want a custom admin page with fields (text, checkbox, textarea) that i could set trough that page and use them global ( example: set my facebook page url from this custom settings page and display it on my public site)

Can somebody give me some instructions? 

Share this post


Link to post
Share on other sites

Hi Madalin,

Welcome to ProcessWire and the forums! :-)

There are a number of ways to achieve this. If it is only a settings page, then you can create the page as a direct child of Admin. I don't know what you mean by "to show as tab with some functionality" but the page should show up as a menu item in Admin. You will need to have a template for that page, of course. Add as many fields as you want to that template that will be used by your "settings" page. You can then pull up data from that page using the PW API, in this case you would want to use $pages since pages in Admin cannot be accessed directly in the frontend (so no $page). 

To output your settings fields...example..

echo $pages->get(12345)->title//Here, 12345 is the ID of your settings page. You can also retrieve the page by its path or title or name...

Have a read here

http://processwire.com/api/variables/pages/

http://processwire.com/api/variables/page/

  • Like 2

Share this post


Link to post
Share on other sites

To output your settings fields...example..

echo $pages->get(12345)->title//Here, 12345 is the ID of your settings page. You can also retrieve the page by its path or title or name...

Have a read here

http://processwire.com/api/variables/pages/

http://processwire.com/api/variables/page/

Thank you! I have understand that but i still have some problems.

Let's say i have http://localhost/processwire/admin/settings/ (where settings is my custom created page)

What is the Process i have to asign to this page and how can i create the template to be shown only to admin interface?

Share this post


Link to post
Share on other sites

"process to assign....":

This tells me you are assigning your 'settings' page the 'wrong' template. Do not assign it the admin template.

1. First create your own template (no need for a template file; just the template). Call that template, say 'settings'.

2. Add the fields you want to that template.

3. Go to Admin (I mean the page Admin in the page tree), create a new page under the 'admin' page. Call it 'settings', give it the template 'settings'....you are good to go.. :-)....

Pages under admin can only be seen by the 'supersuser' - so, no worries that people with the wrong permissions will see it :-). In addition, as I stated, these pages cannot be directly accessed via the frontend + your page will not have a template file....(not that it matters since this is an 'admin' page). 

Have you read up on the docs about how PW works? If not, you might want to do that first :-)

Edited by kongondo
  • Like 2

Share this post


Link to post
Share on other sites

Setup> Templates > Add new template
 
A1400173950563324_1.jpg
 
A1400173950563324_2.jpg
 
Setup > Fields > Add new field
 
A1400173950563324_3.jpg
A1400173950563324_4.jpg
A1400173950563324_5.jpg
 
Thank you, it worked! But notice in the last image the Site Settings link from the menu has disappeared... How to put it back there?

Also... to view this page i need to access http://localhost/processwire/admin/page/edit/?id=1006

Is there a way to view that page at this custom url http://localhost/processwire/admin/settings/ ?

Share this post


Link to post
Share on other sites

Thank you, it worked! But notice in the last image the Site Settings link from the menu has disappeared... How to put it back there?

It seems you unpublished the page?

Also... to view this page i need to access http://localhost/processwire/admin/page/edit/?id=1006

Is there a way to view that page at this custom url http://localhost/processwire/admin/settings/ ?

You are in the backend, one that only you can see, why does it matter to see a pretty URL?  :P OK, what is happening is this. When 'viewing' a page like the one you've created in admin, what you are actually doing is editing it...hence the .../edit/?id=1006. If you want something like .../admin/settings/ what you need is to create a process module or use some other modules available for PW. I am inclined to think, though (apologies if I am wrong) that you are a newbie to PHP as well? I am hesitant to point you to advanced stuff until you at least learn the basics of PW  :lol:

Share this post


Link to post
Share on other sites

It seems you unpublished the page?

You are in the backend, one that only you can see, why does it matter to see a pretty URL?  :P OK, what is happening is this. When 'viewing' a page like the one you've created in admin, what you are actually doing is editing it...hence the .../edit/?id=1006. If you want something like .../admin/settings/ what you need is to create a process module or use some other modules available for PW. I am inclined to think, though (apologies if I am wrong) that you are a newbie to PHP as well? I am hesitant to point you to advanced stuff until you at least learn the basics of PW  :lol:

Here's a tip for making your global settings / global options page easily accessible in the admin, without having to create a custom process module or going to the page using the pagetree.

Let's say the page name of your settings page is called "settings" and it's directly under home.

Now, create a *new* page under the admin page in ProcessWire.  Use the "admin" template.  Call this page "settings" as well.  After saving, it will now give you the option to choose which process module this admin page will utilize.  Choose "ProcessPageEdit".

Now you will have a link in the main navbar to this Settings page, but when you go to it, it will error saying "Unknown page" + "the process returned no content".

What you need to do is make this page load the /settings/ page you originally made.

Using the special "/site/ready.php" file (create ready.php if it doesn't exist), you can add the following line of code to it:

if($page->template=="admin" && $page->name=="settings") $input->get->id = $pages->get("/settings/")->id;

Now go to the Settings page in the navbar.  Nice, easy and "official" feeling.

  • Like 8

Share this post


Link to post
Share on other sites

a other option for own admin pages with custom stuff....would be the

AdminCustomPages Module

https://processwire.com/talk/topic/3474-admin-custom-pages-module/

so you could assign the process AdminCustomPage and choose a "normal" PHP Template....but this not shows up the /settings/ page - this could be used for own output and dashboard like views that could be easy created without the need of a own module in the backend....

For editing /settings/ pages that are not under the /admin/ branch jlahijani's tip should do this..

@jlahijani if you got the time you could send this to the https://processwire-recipes.com/ project...it's a god home for such good hints...

regards mr-fan

  • Like 1

Share this post


Link to post
Share on other sites

@jlahijani - thanks for this, i should add your technique to my settings tutorial.. how do you do settings, e.g. table, text field, regular fields, etc..

https://processwire.com/talk/topic/8373-use-delimited-texarea-table-or-yaml-for-settings/?hl=settings

**just set this up and it works great! (i was using a custom admin page before for this and doing a session redirect..)

Share this post


Link to post
Share on other sites

i create ready.php file and wrote this codes but nothing changed? is it difference between versions? what is it ready.php under /site/ directory?

still error saying "Unknown page

Share this post


Link to post
Share on other sites

Hi folks,

is there any "better" solution for global settings today as written in this thread?

I've a few input fields like website_title and website_image which I want to be editable trough a admin page (e.g. setup > settings) and accessible in my template (e.g. $settings->website_title)

Best regards,
rjgamer

Share this post


Link to post
Share on other sites

Thanks for your links. I already know these solutions. But they are not "user friendly" for non-technical users.

General site settings module is buggy in latest PW dev version and settings factory does not offer a solution based on uikit formatted input forms.

The solution written in this post is perfect for my use case, but I want to prevent to create mulitple settings page under home and admin, only to get it accessible trough "setup > settings".

Offtopic: Cool zgseh dass oh Schwiizer hie mit mache 🙂

Share this post


Link to post
Share on other sites
6 hours ago, rjgamer said:

is there any "better" solution for global settings today as written in this thread?

Did you try this solution?

On 8/4/2015 at 6:50 PM, Jonathan Lahijani said:

Here's a tip for making your global settings / global options page easily accessible in the admin, without having to create a custom process module or going to the page using the pagetree.

Let's say the page name of your settings page is called "settings" and it's directly under home.

Now, create a *new* page under the admin page in ProcessWire.  Use the "admin" template.  Call this page "settings" as well.  After saving, it will now give you the option to choose which process module this admin page will utilize.  Choose "ProcessPageEdit".

Now you will have a link in the main navbar to this Settings page, but when you go to it, it will error saying "Unknown page" + "the process returned no content".

What you need to do is make this page load the /settings/ page you originally made.

Using the special "/site/ready.php" file (create ready.php if it doesn't exist), you can add the following line of code to it:


if($page->template=="admin" && $page->name=="settings") $input->get->id = $pages->get("/settings/")->id;

Now go to the Settings page in the navbar.  Nice, easy and "official" feeling.

 

3 hours ago, dragan said:

Well, feel free to write your own module then. It ain't so hard, really. 

ProcessModules are great for custom user interfaces, but a settings page is - at least how I understand it - primarily for storing some data. That's a little harder to do using ProcessModules and it's exactly what ProcessPageEdit is built for. So I think the solution described by @Jonathan Lahijani is still the best option.

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

yeah, I saw it. But I don't like it, that you have to create a "settings" page under home to store the data. This is very iritiating for a dummy user.

Is there no solution to create a hidden "settings" page and then map it to the admin page?
 

Share this post


Link to post
Share on other sites
1 hour ago, rjgamer said:

I don't like it, that you have to create a "settings" page under home

Normally I create more than that under home anyway, such as custom assets, tags, categories, etc... Normally I create a page under home called something like "Internal" – and move it to be the last one – to signal that pages under that do not directly map to public pages, and I explain it to the client. As it is a simple concept, even the less technically minded had no issues understanding it so far.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
48 minutes ago, szabesz said:

Normally I create more than that under home anyway, such as custom assets, tags, categories, etc... Normally I create a page under home called something like "Internal" – and move it to be the last one – to signal that pages under that do not directly map to public pages, and I explain it to the client. As it is a simple concept, even the less technically minded had no issues understanding it so far.

You are right. I've tested a lot of solutions in last few hours. It seems to be the fastest, most user-friendly and most flexible way to get it done without any third-party module or core manipulation.

  • Like 1

Share this post


Link to post
Share on other sites

I don't know how, but the item in the sidebar ('settings') now keeps linking to /admin/page/settings/bookmarks/

On other sites I made this isn't the problem.

Anyone with he same problem?

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Ivan Gretsky
      Most of us know and use site/config-dev.php file. If present, it is used instead of site/config.php, so it is easy to set database connection and debug mode for local development, not touching the production config. It is also very useful when working with git. You can simply ignore it in the .gitignore file, so local settings won’t end up in the repo.
      But sometimes you need to add code to site/ready.php or site/init.php just for the dev environment. For example, to add ryan’s super cool on demand images mirrorer. I can’t live without it when working with big sites, which have more assets then I want to download to my desktop.
      It would be great if there was something like site/ready-dev.php for this. Not out-of-the-box, but it’s pretty easy to achieve. Unlike site/config-dev.php, site/ready.php is not hardcoded. It’s name is set with a special config setting:
      // wire/config.php $config->statusFiles = array( 'boot' => '', 'initBefore' => '', 'init' => 'init.php', 'readyBefore' => '', 'ready' => 'ready.php', 'readySite' => '', 'readyAdmin' => '', 'render' => '', 'download' => '', 'finished' => 'finished.php', 'failed' => '', ); As you can see, we can not only define, which files are loaded on init, ready and finished runtime states, but probably even add more if we need to.
      So we override this setting in site/config-dev.php like this:
      // site/config-dev.php // Change ready.php to ready-dev.php $temp = $config->statusFiles; $temp['ready'] = 'ready-dev.php'; $config->statusFiles = $temp; For some reason we can’t just do
      $config->statusFiles['ready'] = 'ready-dev.php'; and have to override the whole array. Maybe you PHP gurus can explain this in the comments.
      Now we can create the site/ready-dev.php file and place all the dev-only code there. Important thing is to include the main site/ready.php.
      // site/ready-dev.php include 'ready.php'; // DEV HOOK TO MIRROR ASSETS ON DEMAND $wire->addHookAfter('Pagefile::url, Pagefile::filename', function($event) { $config = $event->wire('config'); $file = $event->return; if($event->method == 'url') { // convert url to disk path $file = $config->paths->root . substr($file, strlen($config->urls->root)); } if(!file_exists($file)) { // download file from source if it doesn't exist here $src = 'https://mysite.com/site/assets/files/'; $url = str_replace($config->paths->files, $src, $file); $http = new WireHttp(); try { $http->download($url, $file); } catch (\Exception $e) { bd($file, "Missing file"); } } }); Do not forget to replace "mysite.com" if you’re copypasting this))
      Now, add the newly created file to the `.gitignore` and we’re done.
       
      # .gitignore # Ignore dev files site/config-dev.php site/ready-dev.php Thanks for reading!
       
    • By Andi
      Getting a little deeper into the ProcessWire state-of-mind here. I seriously think I wouldn't have come back to webdev if it wasn't for this wonderful little gem of a CMS.
      I have an "Options" field added to all users on a site. If the user has anything other then "default" selected, I would like to show a permanent message in the admin like the one in the screenshot, only so that the user can't close it. As a friendly reminder that he changed that option from default to something crazy 🙂
      I've read up on how to send messages to users, but where would I hook into to make this show up all the time in the backend?
      https://processwire.com/api/ref/wire/message/
      Thanks in advance!

    • By BitPoet
      Here's a small new module that adds a "Manage tags" button to the template list, just like the field list already has.
      Easily add, remove and change tags for your templates.
      https://github.com/BitPoet/TemplateTagsEditList

    • By alanxptm
      Hi, first time here.
      I've been working on my first site with PW and it has been a pleasure, I'm around 75% of structure and logic completion I think, and polishing some things now.
      My question is: I have a parent 'category' page that musn't be editable by the author role, but they must be able to add children 'post page' to the 'category'.
      I've been playing with the settings and can just let the author create childs if is able too to edit the parent category, so.. How can I do it?
       
       
    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
×
×
  • Create New...