joey102030 Posted July 31, 2013 Share Posted July 31, 2013 I've been using PW for about a week, and I'm stumbling over something that seems like it should be easy, and it probably is (maybe I'm just missing a trick) In the admin, I've created a new page as a child of 'admin' called 'settings'. I've created and assigned a new template 'settings' and added all the necessary fields to it. Now the new page 'settings' is showing as a link across the top of the admin template as it should (I'm using Futura Remixed but I think it's the same in the default template)... But when I click the link, it shows the page rendered when actually I would like to edit. Looking closer I can see the link at the top is: admin/settings/ But I would I like it to be (something like): admin/page/edit/?id=xxx I hope that makes sense. Link to comment Share on other sites More sharing options...
kongondo Posted July 31, 2013 Share Posted July 31, 2013 (edited) HI joey. Welcome to PW and the forums! A quick one, that's because the code generating that menu at the top outuputs those pages URLs. So clicking on setup, renders setup. Clicking on access renders that...hence, clicking on your "setttings" renders that... This is the line outputting the URLs in the file topnav.inc, specifically the $p->url echo "\n\t\t\t\t<li><a href='{$p->url}'$class>$title</a></li>"; Edited July 31, 2013 by kongondo 1 Link to comment Share on other sites More sharing options...
joey102030 Posted July 31, 2013 Author Share Posted July 31, 2013 HI joey. Welcome to PW and the forums! A quick one, that's because the code generating that menu at the top outuputs those pages URLs. So clicking on setup, renders setup. Clicking on access renders that...hence, clicking on your "setttings" renders that... Thanks Kongondo So, what would be the quickest route to achieve what I'm looking for? Creating a new module seems like overkill to effectively just swap a link around in the page tree. Would the 'Markup Simple Navigation' module give me the flexibility I want? Link to comment Share on other sites More sharing options...
kongondo Posted July 31, 2013 Share Posted July 31, 2013 (edited) Quickest I can think (without much thought )... You can output the p->url conditionally, i.e. something like if ($p->title == "settings") { //href='output link to edit the page' } else { href='{$p->url}'//example, snipped code... } Maybe even assign href value to some variable. This is probably quick and dirty and there could be a better way. Untested and it is just an idea.. Now, very important. Do not edit /wire/templates-admin/topnac.inc. Instead, copy the templates-admin to your site folder. That way, PW will instead serve your site templates-admin instead of the wire one. It will also survive an upgrade... Edit: Corrected code Edited July 31, 2013 by kongondo 1 Link to comment Share on other sites More sharing options...
diogo Posted July 31, 2013 Share Posted July 31, 2013 You can also redirect to the desired link. Put the page there so you have the link on the nav, and on the template: <?php $pageID = 1; $session->redirect($pages->get(10)->url.'?id='.$pageID); // 10 is the ID of the "Edit Page" page in the admin This is a simple redirection, and it's not the ideal of course... 2 Link to comment Share on other sites More sharing options...
joey102030 Posted July 31, 2013 Author Share Posted July 31, 2013 Quickest I can think (without much thought )... You can output the p->url conditionally, i.e. something like if ($p->title == "settings") { //href='output link to edit the page' } else { href='{$p->url}'//example, snipped code... } Maybe even assign href value to some variable. This is probably quick and dirty and there could be a better way. Untested and it is just an idea.. Now, very important. Do not edit /wire/templates-admin/topnac.inc. Instead, copy the templates-admin to your site folder. That way, PW will instead server your site templates-admin instead of the wire one. It will also survive an upgrade... Edit: Corrected code Thanks again Kongondo Yeh I can see how that could work. I'm guessing I could also assign the 'admin' template to the 'settings' page, then create a very simple module (eg. ProcessSettings) to effectively do the above. Although that's all a bit beyond me at this stage. Link to comment Share on other sites More sharing options...
kongondo Posted July 31, 2013 Share Posted July 31, 2013 (edited) No need for a module for such a simple task IMO. Here's the code that is working for me...also borrowing from Diogo's code above . It is the whole topnav.inc amended to suit your need. foreach($pages->get($wire->config->adminRootPageID)->children("check_access=0") as $p) { if(!$p->viewable()) continue; $showItem = $user->isSuperuser() ? true : false; $info = array(); if(!$showItem) { $checkPages = $p->numChildren ? $p->children("check_access=0") : array($p); foreach($checkPages as $child) { if($child->viewable()) { $showItem = true; break; } } } if($showItem) { $class = strpos($page->path, $p->path) === 0 ? " class='on'" : ''; $title = strip_tags((string)$p->get('title|name')); $title = __($title, dirname(__FILE__) . '/default.php'); // translate from context of default.php //AMENDMENTS START HERE $pageID = 22;//in this example, I use PW Setup page id which is "22" if ($p->id == $pageID) {//if the page is the one we want an edit link to //create a new variable $href $href=$pages->get(10)->url.'?id='.$pageID;//based on Diogo's code } else { $href = $p->url;//else href is normal url } echo "\n\t\t\t\t<li><a href='{$href}'$class>$title</a></li>"; //changes made; assigned $href to be value of href='' //AMENDMENTS END HERE } } Try it. Change the value of $pageID to the id of your "settings" page. Of course, you can delete the comments I added to the code if you wish Edited July 31, 2013 by kongondo Link to comment Share on other sites More sharing options...
joey102030 Posted July 31, 2013 Author Share Posted July 31, 2013 No need for a module for such a simple task IMO. Here's the code that is working for me...also borrowing from Diogo's code above . It is the whole topnav.inc amended to suit your need. foreach($pages->get($wire->config->adminRootPageID)->children("check_access=0") as $p) { if(!$p->viewable()) continue; $showItem = $user->isSuperuser() ? true : false; $info = array(); if(!$showItem) { $checkPages = $p->numChildren ? $p->children("check_access=0") : array($p); foreach($checkPages as $child) { if($child->viewable()) { $showItem = true; break; } } } if($showItem) { $class = strpos($page->path, $p->path) === 0 ? " class='on'" : ''; $title = strip_tags((string)$p->get('title|name')); $title = __($title, dirname(__FILE__) . '/default.php'); // translate from context of default.php //AMENDMENTS START HERE $pageID = 22;//in this example, I use PW Setup page id which is "22" if ($p->id == $pageID) {//if the page is the one we want an edit link to //create a new variable $href $href=$pages->get(10)->url.'?id='.$pageID;//based on Diogo's code } else { $href = $p->url;//else href is normal url } echo "\n\t\t\t\t<li><a href='{$href}'$class>$title</a></li>"; //changes made; assigned $href to be value of href='' //AMENDMENTS END HERE } } Try it. Change the value of $pageID to the id of your "settings" page. Of course, you can delete the comments I added to the code if you wish This is perfect, thanks so much! I can see from the documentation I can identify a page by name as well as ID, which will be useful for future projects where I can't be certain of the page ID. Link to comment Share on other sites More sharing options...
kongondo Posted July 31, 2013 Share Posted July 31, 2013 Glad it worked.... Ye, the docs are really helpful. Have a read and ask away if you have questions. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now