Jump to content
MateThemes

Admin Page without Module

Recommended Posts

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!

Share this post


Link to post
Share on other sites

You only need to create a hidden page with blank template let say settings, then put all settings in that page:

$page->rootParent()->child('template=settings, include=hidden');

or put it in _init.php:

$mySettings = $page->rootParent()->child('template=settings, include=hidden');

Share this post


Link to post
Share on other sites
18 hours ago, bernhard said:

Hi,

it would be helpful for everybody to list what you've tried and what did not work and why 😉 

What about https://modules.processwire.com/modules/settings-factory/ ?

As I described in short, I tried it with a custom settings page (with a blank template) under admin. But then no Fields were assigned. I tried it this way because I want to have a native feeling for the settings and the page should appear under the main navigation.

Is there any detailed tutorial for my purpose? I didn't find any.

I didn't know the module "settings factory" I will give it a try.

Share this post


Link to post
Share on other sites

Hi ... Jonathan Lahijani has a great tutorial on youtube that can help you

Simply put, you need to create an option template,
then add 2 pages, one in the page tree named options, to which you choose the option template, and under the admin add another page and change the name, for example (admin_options), so that the names are not identical. Choose a process named ProcessPageEdit and save the page ...
in admin.php paste the code

// Custom Options Page
if( page()->name == 'admin_options' ) input()->get->id = pages()->get('options')->id;

Finally, you can add some css to hide the options page in the page tree.

/** Hook Admin Custom CSS */
$wire->addHookAfter('Page::render', function($event) {
	if(page()->template != 'admin') return; // Check if is Admin Panel
	$value  = $event->return; // Return Content
	$templates = urls()->templates; // Get Template folder URL
	$style = "<link rel='stylesheet' href='{$templates}assets/css/admin.css'>"; // Add Style inside bottom head
	$event->return = str_replace("</head>", "\n\t$style</head>", $value); // Return All Changes
});

You can also download the profile that has the option page created and see how you can create your own options page
https://github.com/rafaoski/site-minimal

 

  • Like 3

Share this post


Link to post
Share on other sites
18 hours ago, rafaoski said:

Hi ... Jonathan Lahijani has a great tutorial on youtube that can help you

Simply put, you need to create an option template,
then add 2 pages, one in the page tree named options, to which you choose the option template, and under the admin add another page and change the name, for example (admin_options), so that the names are not identical. Choose a process named ProcessPageEdit and save the page ...
in admin.php paste the code


// Custom Options Page
if( page()->name == 'admin_options' ) input()->get->id = pages()->get('options')->id;

Finally, you can add some css to hide the options page in the page tree.


/** Hook Admin Custom CSS */
$wire->addHookAfter('Page::render', function($event) {
	if(page()->template != 'admin') return; // Check if is Admin Panel
	$value  = $event->return; // Return Content
	$templates = urls()->templates; // Get Template folder URL
	$style = "<link rel='stylesheet' href='{$templates}assets/css/admin.css'>"; // Add Style inside bottom head
	$event->return = str_replace("</head>", "\n\t$style</head>", $value); // Return All Changes
});

You can also download the profile that has the option page created and see how you can create your own options page
https://github.com/rafaoski/site-minimal

 

Hello!!!

Thank you for the share. This is what I need!!!

What is the best way to get the fields in the template if you want to access them? 

Share this post


Link to post
Share on other sites

The easiest way is to set the options page in the _init.php file:

$siteOptions = $pages->get('/options/');

// If you set setFunctionsAPI ( $config->useFunctionsAPI = true;  ) to true in the configuration file, you can display them in the template in this way

$siteOptions = pages()->get('/options/');

//or
$siteOptions = pages('/options/');

Then in the template just display the fields:

<h1><?= $siteOptions->site_name ?></h1>

<?php
// In the field settings you should select to display a single image
if ($siteOptions->logo): ?>

	<img src="<?= $siteOptions->logo->url ?>" width='100' alt="<?= $siteOptions->logo->description ?>">

<?php endif ?>

Or add new “Unique” status for pages https://processwire.com/blog/posts/pw-3.0.127/
Add this status to the Options page and in the _init.php file get this way:

$siteOptions = pages()->get('options');

// or
$siteOptions = pages('options');

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 7/31/2019 at 7:54 AM, rafaoski said:

The easiest way is to set the options page in the _init.php file:


$siteOptions = $pages->get('/options/');

// If you set setFunctionsAPI ( $config->useFunctionsAPI = true;  ) to true in the configuration file, you can display them in the template in this way

$siteOptions = pages()->get('/options/');

//or
$siteOptions = pages('/options/');

Then in the template just display the fields:


<h1><?= $siteOptions->site_name ?></h1>

<?php
// In the field settings you should select to display a single image
if ($siteOptions->logo): ?>

	<img src="<?= $siteOptions->logo->url ?>" width='100' alt="<?= $siteOptions->logo->description ?>">

<?php endif ?>

Or add new “Unique” status for pages https://processwire.com/blog/posts/pw-3.0.127/
Add this status to the Options page and in the _init.php file get this way:


$siteOptions = pages()->get('options');

// or
$siteOptions = pages('options');

 

 

Hello!!!

Thank you very much for your help!!! It works now like a charm!

  • Like 1

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 codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
      --Pete
    • By vwatson
      I don't have any fontawesome icons in the admin section. Not sure what's wrong. They used to appear. I've tried all the user profiles and they're gone in all of them.
      Using the browser inspector tool, I see this message:
      Access to font at 'https://www.domain.com/wire/templates-admin/styles/font-awesome/fonts/fontawesome-webfont.ttf?v=4.7.0' from origin 'http://domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
      I'm not sure why this is occurring or how to fix it. Any help would be greatly appreciated. 
    • 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

×
×
  • Create New...