Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/12/2017 in all areas

  1. The PW Backend is basically a highly-specialized frontend to your data, so if you set your permissions correctly you can let whoever you want have access to it.
    5 points
  2. @alan - another option would be to paste a list of page titles (one per row) into the Add mode screen of the BatchChildEditor module. No code needed
    3 points
  3. ProcessWire is mentioned in the repository Awesome UIkit:
    2 points
  4. Thanks @Soma, I just created an array in Sublime Text in 3mins and then used a for loop and a modified version your code to create 62 pages in a click, continually amazed by the simple power of PW. PS: This was my code, it's obvious/simple, but just in case there's someone looking for a simple example (caution, only call the function once as it just blasts new pages into creation function make_pages() { $out =''; $mypages = array("1st Degree", "2nd Degree", "3rd Degree", "Abdomen", "Allergic Reaction", "Anger And Indignation", "Animal Bites", "Back", "Bad Fish", "Bad Meat", "Beesting", "Blow To Eardrum", "Blow To Eyes", "Blow To Orbit", "Blow To Outer Ear", "Blow/whiplash", "Body Injury", "Breathway Constriction", "Bruises", "Burns", "Cold", "Crushed Fingers", "Dizziness and Vertigo", "Dog Bites", "Ear", "Emotional Upset", "Extremeities", "Eye", "Fainting/collapse", "Fall On Mouth/teeth", "Fear And Fright", "Food Poisoning", "Fractures", "Frostbite", "General", "Grief And Betrayl", "Head", "Heat", "Heatstroke", "Insect Bites", "Joint Sprain", "Mouth", "Muscular Strains", "Neck", "Nerve Injury", "Nose", "Nosebleed", "Overeating", "Overuse Of Alcohol, Drugs, Tabaco, Food", "Physical Injury", "Poison Ivy", "Puncture Wounds", "Rich Food", "Shock And Loss Of Love", "Skin Rash, Swells", "Snake Bites", "Splinters", "Stomach", "Sunburn/burns", "Teeth", "Throat", "Wounds, Cuts"); $out = count($mypages); for ($counter = 0; $counter < count($mypages); $counter++) { $np = new Page(); // create new page object $np->template = "app_nav"; $np->parent = "/app_nav/"; // or id or page object $np->title = $mypages[$counter]; $np->save(); } return $out; }
    2 points
  5. Try to use wireRenderFile instead
    2 points
  6. Well it wasn't something I tested for specifically, but it was pretty easy to add support for ProFields Textareas so I have done that in v0.0.6.
    2 points
  7. My module was very experimental. Very happy for it to have a successor
    2 points
  8. <?php foreach ( $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date') as $single ) : ?> You can use Start_date>=today as a selector to only show items with a Start_date that is either today or in the future.
    2 points
  9. I'm working on a module that scans the textarea field and imports external images, and replaces the reference to them in the editor with the local version. This is the function that is hooked after Page save. Mods: http://modules.processwire.com/modules/import-external-images/ Github: https://github.com/outflux3/ImportExternalImages
    1 point
  10. Greetings. I am here to share my first module. I make this module because I cannot find one to suit my need. I like SessionHandlerDB but I do not want to use mysql database to store session for performance. So, Redis seems to be the best choice. I have tried to use netcarver's SessionHandlerRedis but it lacks something I need, those are the active session checking and the easy module configuration while I do borrow some code from it (thanks to netcarver). So I take this chance to merge them together to form a new module. I am new to use github and I don't know if it is appropriate to publish another similar project, or fork from them. You may grab this from Github: SessionHandlerDBRedis I hope this could give somebody a help. Updated to v0.4 changelog: v0.3 - added ability to get forwarded IP instead of normal remote IP. v0.4 - added session lock
    1 point
  11. I needed a language switcher so i searched the forum and docs, found very useful stuff, but as im new in processwire (came from joomla) all this is still a bit confusing for me, need time to get use to it i guess. There's probably other people like me get confused in all the power of pw, and need language switcher on the site, so i decided to share what i came up with. Actually its very simple, a lot easier then i thought. There is very nice example in docs using select box (there i found out about $languages array, and its clicked), but you need additional script if you wanna style it, so i came up with something simple: TADAAAAA <?php foreach($languages as $language) : ?> <a href="<?=$page->localUrl($language)?>"><?=$language->title?></a> <?php endforeach;?> Here's another example, but now active language is just a span with active class. (Style used on most websites). <?php foreach($languages as $language) : ?> <?php if($user->language->id == $language->id) :?> <span class="active"><?=$language->title?></span> <?php else : ?> <a href="<?=$page->localUrl($language)?>"><?=$language->title?></a> <?php endif;?> <?php endforeach;?> Here is UIkit dropdown example, same can do with bootstrap, just a bit different markup. <div class="uk-button-dropdown" data-uk-dropdown> <button class="uk-button"><?=$user->language->name?></button> <div class="uk-dropdown uk-dropdown-bottom"> <ul class="uk-nav uk-nav-dropdown"> <?php foreach($languages as $language) : ?> <?php if($user->language->id != $language->id) :?> <li><a href="<?=$page->localUrl($language)?>"><?=$language->title?></a></li> <?php endif;?> <?php endforeach;?> </ul> </div> </div>
    1 point
  12. Hi everyone, Some critical updates this morning: 1) The module stopped doing anything in recent versions of PW 3 - I don't exactly when, but this is now fixed. 2) I also added support for restricting the new Pages > Tree dropdown menu that was added in 3.0.55 Please let me know if you find any problems with these changes or if you find any other situations where the module is no longer working. Given the rapid development of new ways to access the page tree that are being added to PW, I strongly recommend thoroughly testing your site if this module is protecting critical info from certain users. Hopefully everything is already taken care of for the current PW dev version, but with the UiKit admin theme, there could be possible breaks. Thanks for testing and letting me know!
    1 point
  13. I think there is some confusion because the word 'tree' has in the past sometimes been used to refer to the page list (ProcessPageList) but now labels the dropdown 'Tree' menus. To be clear, the intention behind my module is not about preventing roles from accessing the page list, it's about removing the dropdown menus which I consider to be a confusing UI for roles with limited editing access. There is a related GitHub issue open here: https://github.com/processwire/processwire-issues/issues/231
    1 point
  14. Using it for website design, overriding styles all the time. I kind of have liked that you have must buzzword components right at hand, ready to integrate, so when a clients asks: oohhh those nice backgrounds that move around when you scroll, DONE, ohhhh I want all this animated like a disney movie, DONE and so on... I have found some things that I need to hack around but in a much less percentage than Bootstrap, at least in my experience. Though a fellow I am working with now has really spoiled me into noticing that writing your own CSS isn't that hard and just makes less work than reverse engineering a framework.
    1 point
  15. Hi SamC, here is what you are looking for: http://hsrtech.com/wordpress/backup-projects-mamp-using-dropbox/
    1 point
  16. What is the benefit of hiding the Tree menu? If the user clicks on the "Pages" he will get the same content, or am I missing something?
    1 point
  17. This is what I use. It groups items into an array with years as keys, then you iterate over them and display your output. <?php $items = $pages->find('selector'); $grouped = array_reduce($items->getArray(), function (WireArray $carry, Page $item) { $year = date('Y', $item->published); if (!$carry->has($year)) { $carry->set($year, new WireArray()); } $carry->get($year)->add($item); return $carry; }, new WireArray()); ?> <?php foreach ($grouped as $year => $yearItems): ?> <h2>Year: <?= $year ?></h2> <?php foreach ($yearItems as $item): ?> <!-- render your items of certain year here --> <?= $item->title ?> <?php endforeach; ?> <?php endforeach; ?>
    1 point
  18. Hmm, one surprising advantage would be addition of shortcodes like in Wordpress. Modules can require, (install if necessary), then hook into Hanna Code and define their own shortcodes to be used in fields. One example would be <?php class EmbedShortcodes extends Wire implements Module { public static function getModuleInfo() { return [ 'title' => 'Shortcodes', 'version' => '0.0.1', 'author' => 'abdus', 'summary' => 'Adds `embed` shortcode', 'href' => 'https://abdus.co', 'autoload' => true, // set to true if module should auto-load at boot 'requires' => [ 'TextformatterHannaCode', ], 'installs' => ['TextformatterHannaCode'], ]; } public function ready() { $this->addHook('TextformatterHannaCode::getPHP', $this, 'renderEmbed'); } protected function renderEmbed(HookEvent $e) { if($e->arguments(0) === 'embed') { $e->replace = true; $e->return = '<div>embedded output</div>'; } } } This works fine for predefined hanna codes, but, for arbitrary shortcodes, it requires a change in the logic of the module where it fetches available hanna codes from database here <?php protected function getReplacement($name, array $attrs, &$consume) { $database = $this->wire('database'); $sql = 'SELECT `id`, `type`, `code` FROM hanna_code WHERE `name`=:name'; $query = $database->prepare($sql); bd($name, 'before'); $query->bindValue(':name', $name, \PDO::PARAM_STR); $query->execute(); if(!$query->rowCount()) return false; // here if it cannot find the hanna code it does nothing. // rest of the function } It should be refactored instead into ___getReplacement(), which allows defining access to hanna codes outside the DB. Once done, we can just [[embed url=youtube.com/asdfgh]] to embed a video etc.
    1 point
  19. cool, yeah i'm trying to sort out using images on the ProcessGeneralSettings module, and will be hopefully working out how to do this soon...
    1 point
  20. the way to do it would be to have the module create template/field/page to hold the image(s), and then in the module, reference that page..
    1 point
  21. You can find out more about namespaces in ProcessWire 3.x here: https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/ If you cannot figure it out, please provide some more details of your template setup.
    1 point
  22. Hi Robin, Great module. Is the module dialog supposed to allow you to edit existing Hanna Codes? When I double click an existing code, it opens in the dialog but none of the inputs are filled out. If I save, then all of the content disappears. Another issue I ran into after upgrading to the latest build: The cancel button on the dialog no longer works. The JS error I'm getting is: "hannadialog.js?t=2015030801.157:32 Uncaught TypeError: Cannot read property 'setAttribute' of null"
    1 point
  23. Hi! Can you try to use $config->paths->templates in your include_once.
    1 point
  24. Scratch that turns out I had the 'Deference in API as' set to 'Multiple pages' under the fields Details tab. Figured this might be of use to others so i'll leave this here.
    1 point
  25. The simpler solution is to always use: setlocale(LC_NUMERIC, 'C') after setting LC_ALL to custom locale. This helps avoiding a lot of issues as LC_NUMERIC tells the code parser how to output numeric expressions. For instance with: setlocale(LC_ALL, 'it_IT.UTF-8'); 1.234 will be written as 1,234 when used as string, like in string concatenation (as in db query builders) . But database and most other data endpoints still expect 1.234 for decimals. It is always better to use LC_NUMERIC 'C' and call numeric/monetary output formatting helpers explicitly in templates.
    1 point
  26. Well, you know it all depends I prefer UIkit 3 to Bootstrap 3/4 because UIkit 3 is more lightweight and more versatile regarding customizations, and for me it is easier to use.
    1 point
  27. Thanks for your points. It indeed makes less difference for low traffic site where shared hosting is the common choice. I always use cheap VPS plan in DigitalOcean or Linode to gain the largest control for less money so I forgot about shared hosting for long..
    1 point
  28. I see and yes, my opinion is that if someone check this tweak in AOS he would like to have the system templates to be shown by default. Otoh when you're at the templates page and set "No" for system templates, system templates will not be shown because PW adds the url parameter "&system=0" which seemingly overrides AOS. Of course if you navigate elsewhere and go back to the templates page system templates will be back. But you can temporarily hide system templates.
    1 point
  29. Make sure you have debug mode on. PW is fine on 7.1 so there must be a problem in your script which will likely show up with debug on.
    1 point
  30. Thanks netcarver, I will try to make a pr on it. I do think using Redis as the session handler has many advantages such as reduce work load for mysql(if you are using it to store sessions) and performance boot(fastest way at the moment?). I experienced a faster page load after using it, no thorough experiment anyway lol. So, I am surprised that no much dev is interested in this(no reply in the SessionHandlerRedis post last two years!?). I wonder if I missed some drawbacks or this tech is already outdated.
    1 point
  31. I made a PR for it. https://github.com/ryancramerdesign/ProcessHannaCode/pull/19 Changes include: Updating module to ProcessWire namespace. This requires standard library classes be prefixed with \ (PDO -> \PDO etc.) Changing internal references inside ProcessHannaCode for TextFormatterHannaCode to use the module instance in $this->hanna instead. Changing getPHP, getJS, and adding getText method for hooking. This allows hooking into TextformatterHannaCode::getPHP, TextformatterHannaCode::getJS and TextformatterHannaCode::getText. Inside these hooks you check for the hanna code name, then do as you wish, like so wire()->addHookBefore('TextformatterHannaCode::getPHP', function (HookEvent $e) { if($e->arguments(0) === 'refer') { $e->replace = true; $args = $e->arguments(2); // $e->return = wireRenderFile('refer', $args); $e->return = 'rendered template output'; } });
    1 point
  32. No. You need the simplexml module. PW doesn't check if simplexml extension is available during its install. I would post an issue about that: https://github.com/processwire/processwire-issues
    1 point
  33. Yes, PW uses a session cookie, and that's how session cookies work: https://en.wikipedia.org/wiki/HTTP_cookie#Session_cookie You can use the LoginPersist module to stay logged in across browser sessions.
    1 point
  34. I also dislike editing code outside of my IDE. The workaround currently is pretty simple - just set this for all your PHP Hanna codes: include($config->paths->templates . 'hannas/' . $hanna->name . '.php'); But I'm in favour of anything that would make it even easier.
    1 point
  35. You could maybe use image tags and set a specific tag...
    1 point
  36. Hi and welcome @ren! I recommend you install the Tracy Debugger module as you'll find this an essential tool when developing. Then you can dump the $page object above your if() conditional and explore what its properties are (parent, url, etc). It should be obvious then why $page will or will not match those conditions you have set. // do not redirect if page matches: bd($this->page, 'page'); if($this->page->template != "admin" // any non-admin page || $this->page->is($this->redirectPage) // the dashboard page (prevent infinite loop) || $this->page->parent->is('/admin/login/') // various attempts to allow logging out || $this->wire("process") == 'ProcessLogin' || strpos($this->page->url, $this->wire('config')->urls->admin . 'login/logout') !== false ) { return; }
    1 point
  37. Welcome back GuruMeditation! 1. I wish there exist something like that. While we are figuring out how to do it, you can show your interest by supporting the basic here (like or something...) EDIT: do not for get @teppo's Weekly Newsletter: https://weekly.pw/ which might be used to skim through all the happenings. 2. Time will tell, but your question is a valid one. UIkit keeps evolving too, so it should be updated from time to time. Things are still in beta stage.
    1 point
  38. @LMD, thanks for the report. Please update to v.0.04 where this issue should be fixed.
    1 point
  39. This module is just what I was looking for! I'm using it to create links to a file download page, instead of to the file itself, with the 'dynamic options' method. However, although it works perfectly, I'm getting a strange error in the Hanna dialogue modal window (see screenshot): I have tried deleting the file compiler cache, but it did not resolve the issue. Set-up Info: Hanna Code: ver. 0.2.0 HannaCode Dialogue: ver. 0.0.3 ProcessWire: ver. 3.0.58 PHP: ver. 5.6.21
    1 point
  40. Hi, https://github.com/plauclair/PW-Branding
    1 point
  41. ..., and you should enable the IMagick Imagesizer Engine if your server supports it! (under PW 3) ..., and additionally to the quality-value, you can try out differend sharpening values (none, soft, medium, strong)
    1 point
  42. Yeah, I Know.. but with PW you can do whatever you want!! lol
    1 point
  43. I am glad that this project is helping ProcessWire getting more devs on board :). I just want to say that I wouldn't have been able to finish ProcessVue if it wasn't for the amazing ProcessWire community. I believe that the community truly is the biggest selling point for new users (like me). Before trying ProcessWire I used OctoberCMS for a while but when I was stuck I got 0 support from the forums, so...althought the CMS is based on the amazing Laravel framework, I just left! I think that ProcessWire is extremely powerful and flexible and with time will become the tool of choice for frontend developers, the new GraphQL module will also help on this direction. Droves of frontend developers are looking for a CMS like this, they just don't know it exists! The usual keywords they use when looking for a SPAs CMS is "Decoupled CMS" or "Headless CMS", and I believe that that's exactly what ProcessWire is for! Some frontend developers prefer to use NodeJS, but the learning curve is huge if you need it for a non trivial project, and the worst thing of all is that after two weeks ANY js tool you may have used is outdated. See for example how Angular has been replaced with React or Vue, and Gulp with Webpack. That doesn't mean that I am against improvements in this regard, I just feel that it's just too much for us poor frontend devs to cope with! ProcessWire is stable, easy to use and won't change API every week. BTW, after that I migrate ProcessVue to GraphQL I am also planning to add Auth0 login integration with JWT, as I think that login/signup is a common feature in SPAs. I am sure I'll have to annoy @Nurguly Ashyrov and the rest of ProcessWire community for getting it in sync with ProcessWire users, but the result should be quite useful
    1 point
  44. Never done it myself, but I know it's possible to decouple the image processing and keep the goodies on an API for manipulation, similar to PW's. You can take a look at Cloudinary feature to upload an image by its URL. Also, there's IMGIX .
    1 point
  45. But what file were those line in?
    1 point
  46. Yeah, everything before line 13 shouldn't be there.
    1 point
  47. This happens when the user PHP runs as isn't the owner of the cache files. The file compiler tries to update the cache files with the modification time of their originals, and while writing to that file can succeed through group permissions, updating the modification time fails unless issued by the owner. Clearing the cache removes the cache files and recreates them with the PHP user as the owner, so the problem is gone.
    1 point
  48. Been getting questions on how to build complex/custom menus. Even with the ability to pass it custom options, some menus are a bit more complex than what Menu Builder offers out of the box. My answer to such questions has, to date, been get the JSON and use that to build your menu. Not very easy for some....but no more...thanks to @Beluga, @Peter and @Webrocker + others for the inspiration/challenges. I've now added a method in MarkupMenuBuilder to make building custom complex menus a breeze. Don't get me wrong, you still have to know your foreach loops or even better grab one of the many recursive list/menu functions in the forums (or StackOverflow) and adapt it to your needs. Don't worry though, below, I provide a couple of complete code examples using recursive functions. For a 2-level deep menu, even a nested foreach would do. Going forward, this new method is what I recommend for building complex menus if using Menu Builder. The new method is called getMenuItems($menu, $type = 2, $options = null) takes 3 arguments. Before I show you the cool things you can do with this method, let's get familiar with the arguments. $menu: This is identical to the first argument in MarkupMenuBuilder's method render(): Use this argument to tell getMenuItems() the menu whose items you want returned. The argument takes a Page, id, title, name or array of menu items $type: Whether to return a normal array or a Menu object (WireArray) of menu items $options: Similar to render() method options but please note that only 3 options (from the list of those applicable to render()) apply to getMenuItems(). These are default_title, default_class and current_class_level. default_class is applied to the item's property $m['ccss_itemclass']. Probably not many know that MarkupMenuBuilder ships with a tiny but useful internal class called Menu. MenuBuilder uses it internally to build Menu objects that are finally used to build menus. Menu objects are WireArrays. If $type == 2, this is what is returned. Array vs WireArray So, which type of output should you return using getMenuItems()? Well, it depends on your needs. Personally, I'd go for the Menu object. Here's why: Although you can still easily build menus by using getMenuItems() to return a normal PHP Array, it's not nearly as powerful as returning and using a WireArray Menu object instead. Whichever type of items you return using getMenuItems(), it means you can manipulate or apply logic before or within a recursive function (or foreach loop) to each of your menu items. For instance, show some parts of the menu only to users who are logged in, or get extra details from a field of the page represented by the menu item, add images to your menu items, etc. Grabbing the Menu object means you can easily add some runtime properties to each Menu object (i.e. each menu item). If you went with a normal array, of course, you can also manipulate it, but not as easily as working with an object. A Menu object also means you have access to the powerful WireArray methods (don't touch sort though!). For instance, $menuItems->find("parentID=$m->id"). With a Menu object, you also get to avoid annoying isset(var) that come with arrays . Here are the properties that come with each Menu object. Use these to control your logic and output menu items values. In that block of code, to the left are the indices you'd get with a normal array. The values (to the right) are the Menu object properties. Below are examples of building the W3Bits 'CSS-only responsive multi-level menu' as illustrated in the tutorial by @Beluga. We use 3 different recursive functions to build the menu using items returned by getMenuItems(). I will eventually expound on and add the examples to my Menu Builder site. Meanwhile, here's a (very colourful) demo. Examples @note: The CSS is the one by @Beluga in the tutorial linked to above. @note: Clearer examples can be found in these gists. First, we grab menu items and feed those to our recursive functions. $mb = $modules->get('MarkupMenuBuilder');// get Menu Builder // get menu raw menu items. $menu can be a Page, an ID, a name, a title or an array #$menu = $pages->get(1299);// pass a Page #$menu = 1299;// pass an ID #$menu = 'main';// pass a name $jsonStr = $pages->get(1299)->menu_items; $arrayFromJSON = json_decode($jsonStr, true); #$menu = $arrayFromJSON;// pass an array $menu = 'Main';// pass a title /** grab menu items as WireArray with Menu objects **/ // for examples 1a, 2 and 3 $menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)} #$menuItems = $mb->getMenuItems($menu);// called without options; 2nd argument defaults to 2 /** grab menu items as Normal Array with Menu items **/ // only for example 1b below menuItems2 = $mb->getMenuItems($menu, 1);// called without options; 2nd argument is 1 so return array Example 1a: Using some recursive function and a Menu object /** * Builds a nested list (menu items) of a single menu. * * A recursive function to display nested list of menu items. * * @access private * @param Int $parent ID of menu item. * @param Array $menu Object of menu items to display. * @param Int $first Helper variable to designate first menu item. * @return string $out. * */ function buildMenuFromObject($parent = 0, $menu, $first = 0) { $out = ''; $has_child = false; foreach ($menu as $m) { $newtab = $m->newtab ? " target='_blank'" : ''; // if this menu item is a parent; create the sub-items/child-menu-items if ($m->parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items // if this is the first child if ($has_child === false) { $has_child = true;// This is a parent if ($first == 0){ $out .= "<ul class='main-menu cf'>\n"; $first = 1; } else $out .= "\n<ul class='sub-menu'>\n"; } $class = $m->isCurrent ? ' class="current"' : ''; // a menu item $out .= '<li' . $class . '><a href="' . $m->url . '"' . $newtab . '>' . $m->title; // if menu item has children if ($m->isParent) { $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m->title) . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="' . wire('sanitizer')->pageName($m->title) . '">'; } else $out .= '</a>'; // call function again to generate nested list for sub-menu items belonging to this menu item. $out .= buildMenuFromObject($m->id, $menu, $first); $out .= "</li>\n"; }// end if parent }// end foreach if ($has_child === true) $out .= "</ul>\n"; return $out; } Example 1b: Using some recursive function and a Menu array /** * Builds a nested list (menu items) of a single menu from an Array of menu items. * * A recursive function to display nested list of menu items. * * @access private * @param Int $parent ID of menu item. * @param Array $menu Array of menu items to display. * @param Int $first Helper variable to designate first menu item. * @return string $out. * */ function buildMenuFromArray($parent = 0, $menu, $first = 0) { $out = ''; $has_child = false; foreach ($menu as $id => $m) { $parentID = isset($m['parent_id']) ? $m['parent_id'] : 0; $newtab = isset($m['newtab']) && $m['newtab'] ? " target='_blank'" : ''; // if this menu item is a parent; create the sub-items/child-menu-items if ($parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items // if this is the first child if ($has_child === false) { $has_child = true;// This is a parent if ($first == 0){ $out .= "<ul class='main-menu cf'>\n"; $first = 1; } else $out .= "\n<ul class='sub-menu'>\n"; } $class = isset($m['is_current']) && $m['is_current'] ? ' class="current"' : ''; // a menu item $out .= '<li' . $class . '><a href="' . $m['url'] . '"' . $newtab . '>' . $m['title']; // if menu item has children if (isset($m['is_parent']) && $m['is_parent']) { $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m['title']) . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="' . wire('sanitizer')->pageName($m['title']) . '">'; } else $out .= '</a>'; // call function again to generate nested list for sub-menu items belonging to this menu item. $out .= buildMenuFromArray($id, $menu, $first); $out .= "</li>\n"; }// end if parent }// end foreach if ($has_child === true) $out .= "</ul>\n"; return $out; } For example 1a and 1b we call the respective functions to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php // build menu from Menu object (example 1a) echo buildMenuFromObject(0, $menuItems); // OR build menu from array (example 1b) #echo buildMenuFromArray(0, $menuItems2); ?> </nav> </div> Example 2: Using a modified version of @mindplay.dk's recursive function /** * Recursively traverse and visit every child item in an array|object of Menu items. * * @param Menu item parent ID $parent to start traversal from. * @param callable $enter function to call upon visiting a child menu item. * @param callable|null $exit function to call after visiting a child menu item (and all of its children). * @param Menu Object|Array $menuItems to traverse. * * @see Modified From mindplay.dk https://processwire.com/talk/topic/110-recursive-navigation/#entry28241 */ function visit($parent, $enter, $exit=null, $menuItems) { foreach ($menuItems as $m) { if ($m->parentID == $parent) { call_user_func($enter, $m); if ($m->isParent) visit($m->id, $enter, $exit, $menuItems); if ($exit) call_user_func($exit, $m); } } } For example 2, we call the function (@note: a bit different from example 1 and 3) this way to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php echo "<ul class='main-menu cf'>"; visit( 0// start from the top items , // function $enter: <li> for a single menu item function($menuItem) { echo '<li><a href="' . $menuItem->url . '">' . $menuItem->title; if ($menuItem->isParent) { echo '<span class="drop-icon">▼</span>' . #'<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($menuItem->title) . '" onclick>▼</label>' . '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $menuItem->id . '" onclick>▼</label>' . '</a>' . #'<input type="checkbox" id="' . wire('sanitizer')->pageName($menuItem->title) . '"><ul class="sub-menu">' . '<input type="checkbox" id="sm' . $menuItem->id . '"><ul class="sub-menu">'; } else echo '</a>'; }// end function 1 ($enter) , #function $exit: close menu item <li> and sub-menu <ul> tags function($menuItem) { if ($menuItem->isParent) echo '</ul>'; echo '</li>'; }, $menuItems// the menu items (Menu objects in this example) ); ?> </nav> </div> Example 3: Using a modified version of @slkwrm's recursive function /** * Recursively traverse and visit every child item in an array|object of Menu items. * * @param Menu Object|Array $menuItems to traverse. * @param Int $parent ID to start traversal from. * @param Int $depth Depth of sub-menus. * @param Int $first Helper variable to designate first menu item. * @see Modified From @slkwrm * @return string $out. */ function treeMenu($menuItems, $parent, $depth = 1, $first = 0) { $depth -= 1; if ($first == 0){ $out = "\n<ul class='main-menu cf'>"; $first = 1; } else $out = "\n<ul class='sub-menu'>"; foreach($menuItems as $m) { if ($m->parentID == $parent) { $sub = ''; $out .= "\n\t<li>\n\t\t<a href='" . $m->url . "'>" . $m->title; if($m->isParent && $depth > 0 ) { $sub = str_replace("\n", "\n\t\t", treeMenu($menuItems, $m->id, $depth, $first)); $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $m->id . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="sm' . $m->id . '">' . $sub . "\n\t"; } else $out .= "</a>\n\t"; $out .="\n\t</li>"; } }// end foreach $out .= "\n</ul>"; return $out; } For example 3, we call the function to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php //parameters: menuItems, menu item parent ID, depth, first (helper variable) echo treeMenu($menuItems, 0, 4); ?> </nav> </div>
    1 point
  49. The forum is full of example for it if you search for it enough Basic code needed to add new pages would be. $np = new Page(); // create new page object $np->template = "basic-page"; $np->parent = "/about/"; // or id or page object $np->title = "Hello World"; $np->save(); It's very easy once you get the hang of it. There's a lot more you can do and sometimes it can be handy to know it to import stuff and create pages via API or in modules. If you want to can take a look at my super duper page creation tool, which is a work in progress but you can add endless amount of pages while looking TV. http://processwire.com/talk/topic/2138-process-tools-create-pages-wip/
    1 point
×
×
  • Create New...