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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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?
    • By Noel Boss
      Admin Theme Boss
      A light and clear theme based on Uikit 3
      Features
      Five unique color options Beautifully redesigned login screens Modern typography using Roboto Condensed Extended breadcrumb with edit links Extends AdminThemeUikit, so you can continue using all current and future AdminThemeUikit features Option to activate theme for all users Compatibility with AdminOnStreoids and other third party modules   Updated and Releases
      There is a shiny new release page where you can subscribe to updates for new releases of AdminThemeBoss.   Color Variants:
      ProcessWire Blue


       
      Dark Black


       
      Vibrant Blue

       
      Happy Pink

      Smooth Green *new with 0.6.1*

       
      Requirements
      Requires a current ProcessWire version with AdminThemeUikit installed and activated.
      Installation
      Make sure AdminThemeUikit is activated Go to “Modules > Site > Add New“ Paste the Module Class Name “AdminThemeBoss“ into the field “Add Module From Directory“ Click “Download And Install“ On the overview, click “Download And Install“ again… On the following screen, click “Install Now“

      Manual Installation
      Make sure the above requirements are met Download the theme files from GitHub or the ProcessWire Modules Repository. Copy all of the files for this module into /site/modules/AdminThemeBoss/ Go to “Modules > Refresh” in your admin Click “Install“ on the “AdminThemeBoss“ Module
    • By Clément Lambelet
      Hey!
      I've been working on a Processwire installation (3.0.123) for a few days now and I must have made a big mistake this morning because the links in the admin's main menu no longer appear.
      This is not related to the admin theme, because the bug occurs with all themes (Default, Reno, Uikit).
      I tried to reinstall with the dev version (3.0.136), but the problem is still there. I also uninstalled all the modules I had added, without success. There is no error in the js console. 
      I still can access/view/edit the pages  by going through the admin/page list.
      Thanks in advance for your help!


    • By MateThemes
      Hello everyone!
      I have searched the forum for quite a long time and I tried some solutions for my topic but nothing seems to work.
      I need to create a Settings Page and for a native feeling I want to create it under the main navigation on top. The settings page should hold the Main Logo, some styling and other settings. As I said nothing seems to work for me. I tried to create a Page under Admin with Admin Template and ProcessPageEdit but then I can't assign an image field. 
      I don't want to write a module because it is to much work for only 3 settings.
      I hope someone of the forum could help me out!
      Have a nice day!
×
×
  • Create New...