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 7

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

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 Noel Boss
      Admin Theme Boss
      A light and clear theme based on Uikit 3
      Features
      Four unique color options Beautifully redesigned login screens Modern typografy 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   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

      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 benbyf
      I always seem to get this warning on every new install of PW on my Ubuntu 14 box with Digital Ocean. The servers are usually based in the UK and I was wondering if I should be adding something other than the below in the config? Is there a UK based locale code? Quick Google didnt come up with much.
      Warning: your server locale is undefined and may cause issues. Please add this to /site/config.php file (adjust “en_US.UTF-8” as needed): setlocale(LC_ALL,'en_US.UTF-8');
      Added to the config file:
      setlocale(LC_ALL,'en_US.UTF-8');  
    • By mjut
      Hello!
      I am trying to get some extra css-file into my admin templates. I managed to modify my admin.php to this:
      <?php namespace ProcessWire; require($config->paths->adminTemplates . 'controller.php'); echo "<link rel='stylesheet' type='text/css' href='" . $config->urls->templates . "css/admin.css'>"; By doing so, the css <link> is added to the very end of each parsed admin-html. (right AFTER the closing </body> tag.)
      That causes some trouble. e.g. the page tree is not displaying any more. Although, other pages are working - like the edit form of a page.
      My question: is there a correct way of adding my extra css to the admin area?
      Thanks for you help!
      Stephan
       
    • By LukeCage
      Hi! I have a big problem with a client of mine. I have to do something that i don't do very often with processwire, and i'm very afraid that i'm not gonna able to do it. So i write to search some help from you experts.
      The website that i'm gonna create will have a database with infos about users. This users are not the actual registrered users, but possible users. I'll try my best to explain this. What i will have is a datasheet in the database with infos about all the users (name, surname, fiscal Code) that can register to the website. So during registration the website is confront with this database of people, and accept or not your registration to the website.
      Now. The problems are: the client need a page in the CMS to insert this people in the first place (Custom Admin Page?) in the database. I read what i need to create it, but i don't understand what i need to do next. What i need to do for reading and writing to the database, with data, directly from a custom admin page in processwire?
      The other thing is. I can do this control during registration? I Can extend fields in the user account?
      I'm completely in your hands.
    • By Robin S
      Breadcrumb Dropdowns
      Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.

      Installation
      Install the Breadcrumb Dropdowns module. The module requires ProcessWire >= v3.0.83 and AdminThemeUikit.
      There is a checkbox option in the module config that determines if the breadcrumb dropdowns will include pages that the user does not have permission to edit.
      Features/details
      The module adds an additional breadcrumb item at the end for the currently edited page. That's because I think it's more intuitive for the dropdown under each breadcrumb item to show the item's sibling pages rather than the item's child pages. In the dropdown menus the current page and the current page's parents are highlighted in a crimson colour to make it easier to quickly locate them in case you want to edit the next or previous sibling page. Unpublished and hidden pages are indicated in the dropdowns with similar styling to that used in Page List. If the option to include uneditable pages is selected then those pages are indicated by italics with a reduced text opacity and the "not-allowed" cursor is shown on hover. There is a limit of 25 pages per dropdown for performance reasons and to avoid the dropdown becoming unwieldy. If the current user is allowed to add new pages under the parent page an "Add New" link is shown at the bottom of the breadcrumb dropdown. If the currently edited page has children or the user may add children, a caret at the end of the breadcrumbs reveals a dropdown of up to the first 25 children and/or an "Add New" link. Overriding the listed siblings for a page
      If you want to override the siblings that are listed in the dropdowns you can hook the BreadcrumbDropdowns::getSiblingsmethod and change the returned PageArray. For most use cases this won't be necessary.
      Incompatibilities
      This module replaces the AdminThemeUikit::renderBreadcrumbs method so will potentially be incompatible with other modules that hook the same method.
       
      https://modules.processwire.com/modules/breadcrumb-dropdowns/
      https://github.com/Toutouwai/BreadcrumbDropdowns