-
Posts
733 -
Joined
-
Last visited
-
Days Won
9
Everything posted by SamC
-
Hold the bells! This works: // main.php <nav id="main-menu"> <?php $arr = $home->and($home->children); echo renderMenu($arr); ?> </nav> // _func.php /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu($items) { // if we were given a single Page rather than a group of them, we'll pretend they // gave us a group of them (a group/array of 1) if($items instanceof Page) { $items = array($items); } $str = ''; foreach ($items as $item) { if ($item->showInMenu == true) { $menuText = $item->get('menuLinkTitle|title'); $currentClass = ''; if (wire('page')->id == $item->id) { $currentClass .= "class=\"current\" "; } elseif (wire('page')->parents->has($item) && !($item->id == 1)) { $currentClass .= "class=\"current-parent\" "; } else { $currentClass .= ''; } $str .= "<li><a " . $currentClass . "href=\"$item->url\">$menuText</a>"; if (!(wire('page')->id == 1)) { if (wire('page')->id == $item->id) { $str .= renderMenu($item->children); } if (wire('page')->parents->has($item) && !($item->id == 1)) { $str .= renderMenu($item->children); } } $str .= "</li>"; } } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul>$str</ul>"; } return $str; } I guess I could combine to two ifs into an || but would make one huge difficult to read line. Maybe just talking this out to myself writing it helped me out. Anyway, any improvements are now welcome I still don't understand what 'wire('page')->parents->has($item)' does. Not just being happy with it working, I now have to know why it works... so testing output, I get this: // _func.php (in loop) echo $item . " | "; // main.php <nav id="main-menu"> <?php $arr = $home->and($home->children); // this same thing passed on every page echo renderMenu($arr); ?> </nav> // OUTPUT TO WEBPAGE // when on home, outputs: 1 | 1015 | 1018 | 1019 | 1022 | 1023 | // when on contact page, outputs: 1 | 1015 | 1018 | 1019 | 1022 | 1023 | // when on about page outputs: 1 | 1015 | 1016 | 1017 | 1018 | 1019 | 1022 | 1023 | // when on subpage of about, outputs: 1 | 1015 | 1016 | 1017 | 1018 | 1019 | 1022 | 1023 | // when on volunteer page, outputs: 1 | 1015 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | // when on subpage of volunteer, outputs: 1 | 1015 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | I'm a little confused here. I thought the array going into 'renderMenu($items)' was the same every time?!
-
Ok, so this gets me some output when the conditions are correct: // _func.php if (wire('page')->id == $item->id) { $str .= renderMenu($item->children); } if (wire('page')->parents->has($item) && !($item->id == 1)) { echo "stuff"; } Still unsure how to get: renderMenu($page->parent->children) ...into my template.
-
Hi, I've been on this for the past couple of hours but can't translate something from a template into a function. I want to print a menu like this: Link 1 Link 2 (active) - Link 2.1 - Link 2.2 Link 3 Link 4 OR Link 1 Link 2 - Link 2.1 (active) - Link 2.2 Link 3 Link 4 ...where the child links are visible when on the parent page AS WELL AS when on a child page. I had this in a template: // main.php <div id="main-menu-wrapper"> <div class="container"> <nav id="main-menu"> <?php $arr = $home->and($home->children); echo renderMenu($arr); ?> </nav> </div> </div> <!-- sub navigation --> <?php if (!($page->id == 1)): ?> <?php if ($page->numChildren > 0): ?> <div id="sub-menu-wrapper"> <div class="container"> <nav id="sub-menu"> <?php echo renderMenu($page->children); ?> </nav> </div> </div> <?php endif; ?> <?php if (count($page->parents) > 1): ?> <div id="sub-menu-wrapper"> <div class="container"> <nav id="sub-menu"> <?php echo renderMenu($page->parent->children); ?> </nav> </div> </div> <?php endif; ?> <?php endif; ?> ...and the function was this: /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu($items) { // if we were given a single Page rather than a group of them, we'll pretend they // gave us a group of them (a group/array of 1) if($items instanceof Page) { $items = array($items); } $str = ''; foreach ($items as $item) { if ($item->showInMenu == true) { $menuText = $item->get('menuLinkTitle|title'); $currentClass = ''; if ($item->id == wire('page')->id) { $currentClass .= "class=\"current\" "; } elseif (wire('page')->parents->has($item) && !($item->id == 1)) { $currentClass .= "class=\"current-parent\" "; } else { $currentClass .= ''; } $str .= "<li><a " . $currentClass . "href=\"$item->url\">$menuText</a></li>"; } } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul>$str</ul>"; } return $str; } Now I've changed my layout and want just a single menu, but with the same functionality. I'm doing it like this: // main.php <nav id="main-menu"> <?php $arr = $home->and($home->children); echo renderMenu($arr); ?> </nav> ...with a function like this: /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu($items) { // if we were given a single Page rather than a group of them, we'll pretend they // gave us a group of them (a group/array of 1) if($items instanceof Page) { $items = array($items); } $str = ''; foreach ($items as $item) { if ($item->showInMenu == true) { $menuText = $item->get('menuLinkTitle|title'); $currentClass = ''; if (wire('page')->id == $item->id) { $currentClass .= "class=\"current\" "; } elseif (wire('page')->parents->has($item) && !($item->id == 1)) { $currentClass .= "class=\"current-parent\" "; } else { $currentClass .= ''; } $str .= "<li><a " . $currentClass . "href=\"$item->url\">$menuText</a>"; if (!(wire('page')->id == 1)) { if (wire('page')->id == $item->id) { $str .= renderMenu($item->children); } // if the current page has omre than 1 parent (i.e. on level 2) if (count(wire('page')->parents) > 1) { // send array of the children of the current pages parent to renderMenu $str .= renderMenu(wire('page')->parent->children); // this is where the function poos the bed } } $str .= "</li>"; } } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul>$str</ul>"; } return $str; } So it works ok when on 'Link 2', you get 'Link 2.1' and 'Link 2.2' printed in a nested list. However, clicking on Link 2.1 or Link 2.2, just a spinning wheel in the browser and a timeout, like I'm stuck in an infinite loop. It's obviously wrong, but can someone please explain what's wrong with it? Why does: <?php echo renderMenu($page->parent->children); ?> ...work in the template, but: $str .= renderMenu(wire('page')->parent->children); ...fails in my function? A bit confused here. Any help is much appreciated. Thanks.
-
Thanks, makes sense.
-
Get page data from an array of pages, whats the quickest method
SamC replied to cb2004's topic in General Support
This is most interesting. I have similar calls to action and was going to create new pages with a link field in order to link to other pages, then just loop through them. But since I know the IDs, and the calls to action are unlikely to change much, this is both quicker and easier Thanks. -
Ok, so I know this is pretty old. However, I just bumped into this exact issue helping my stepson make his own website. It was a wordpress theme and I thought it would be a good idea (for both of us to learn something) and change this static site into a dynamic PW one! So we got to work, everything ran quite smooth apart from the backstretch jQuery plugin and image paths: http://srobbin.com/jquery-plugins/backstretch/ This is called in main.js: $(".image-background").backstretch("images/image-bg.jpg"); ...so Ryans' suggestion worked as follows: $(".image-background").backstretch(templatesURL + "images/image-bg.jpg"); ..and the class is on the actual PW page like this: //main.php <head> <!-- stuff --> <script> var templatesUrl = '<?php echo $config->urls->templates ?>'; </script> </head> <body class="image-background"> <!-- stuff here --> <script type="text/rocketscript" data-rocketsrc="js/main.js"></script> </body> ...so now on every page the background image works as expected. Previously it worked only on the homepage, I presume js paths are relative to where the script is called rather from the files location. I used unminify here for the entire file which I can share. Neither of us wrote this and I have no idea what most of it even does, it was included in the theme, but you can see where this is called (about 4 blocks in): // main.js (function($) { "use strict"; if (navigator.userAgent.match(/IEMobile\/10\.0/)) { var msViewportStyle = document.createElement("style"); msViewportStyle.appendChild(document.createTextNode("@-ms-viewport{width:auto!important}")); document.getElementsByTagName("head")[0].appendChild(msViewportStyle); } $(function() { var nua = navigator.userAgent var isAndroid = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1 && nua.indexOf('Chrome') === -1) if (isAndroid) { $('select.form-control').removeClass('form-control').css('width', '100%') } }) $(window).load(function() { var preloaderDelay = 350, preloaderFadeOutTime = 800; function hidePreloader() { var loadingAnimation = $('#loading-animation'), preloader = $('#preloader'); loadingAnimation.fadeOut(); preloader.delay(preloaderDelay).fadeOut(preloaderFadeOutTime); } hidePreloader(); }); $(".image-background").backstretch("images/image-bg.jpg"); if ($('body').hasClass('parallax-background')) { $.parallaxify({ positionProperty: 'transform', responsive: true, motionType: 'natural', mouseMotionType: 'performance', motionAngleX: 70, motionAngleY: 70, alphaFilter: 0.5, adjustBasePosition: true, alphaPosition: 0.025, }); } $(".particle-background").backstretch("../../assets/images/bg/particle-bg.jpg"); $('.particles').particleground({ dotColor: '#5cbdaa', lineColor: '#5cbdaa', parallax: false, }); $(".snowdrops-background").backstretch("../../assets/images/bg/snowdrops-bg.jpg"); $(".video-background").backstretch("../../assets/video/Storm_darck.jpg"); $(".player").each(function() { $(".player").mb_YTPlayer(); }); $('#clock-countdown').countdown('2018/12/30 12:00:00').on('update.countdown', function(event) { var $this = $(this).html(event.strftime('' + '<div class="counter-container"><div class="counter-box first"><div class="number">%-D</div><span>Day%!d</span></div>' + '<div class="counter-box"><div class="number">%H</div><span>Hours</span></div>' + '<div class="counter-box"><div class="number">%M</div><span>Minutes</span></div>' + '<div class="counter-box last"><div class="number">%S</div><span>Seconds</span></div></div>')); }); $('.flexslider').flexslider({ animation: "fade", animationLoop: true, slideshowSpeed: 7000, animationSpeed: 600, controlNav: false, directionNav: false, keyboard: false, start: function(slider) { $('body').removeClass('loading'); } }); $(document).ready(function() { $("#owl-demo").owlCarousel({ autoPlay: 3000, items: 4, itemsDesktop: [1199, 3], itemsDesktopSmall: [979, 3] }); }); $("html").niceScroll({ cursorcolor: '#ccc', cursoropacitymin: '0', cursoropacitymax: '1', cursorwidth: '3px', zindex: 10000, horizrailenabled: false, }); $('.animated').appear(function() { var element = $(this), animation = element.data('animation'), animationDelay = element.data('animation-delay'); if (animationDelay) { setTimeout(function() { element.addClass(animation + " visible"); }, animationDelay); } else { element.addClass(animation + " visible"); } }); function initContactForm() { var scrollElement = $('html,body'), contactForm = $('.contact-form'), form_msg_timeout; contactForm.on('submit', function() { var requiredFields = $(this).find('.required'), formData = contactForm.serialize(), formAction = $(this).attr('action'), formSubmitMessage = $('.response-message'); requiredFields.each(function() { if ($(this).val() == "") { $(this).addClass('input-error'); } else { $(this).removeClass('input-error'); } }); function validateEmail(email) { var exp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return exp.test(email); } var emailField = $('.contact-form-email'); if (!validateEmail(emailField.val())) { emailField.addClass("input-error"); } if ($(".contact-form :input").hasClass("input-error")) { return false; } else { clearTimeout(form_msg_timeout); $.post(formAction, formData, function(data) { formSubmitMessage.text(data); requiredFields.val(""); form_msg_timeout = setTimeout(function() { formSubmitMessage.slideUp(); }, 5000); }); } return false; }); } initContactForm(); })(jQuery); Anyway, I am relatively new to javascript but how would you go about making this variable (var templatesUrl) available to main.js without plonking it on the global object? I haven't actually got to jQuery yet, still on vanilla javascript (currently on closures, apply, call and bind), but thought I'd better get a decent grip on that first. I tried putting '<?php echo $config->urls->templates ?>' straight into the main.js but it didn't work. Part of me says "of course not, that's php in a js file", but the other part of me says, "but it works within the script tag didn't it?!". Clueless. Any help is most appreciated. Thanks.
-
I know you're going to wait awhile, but I'm only just back from work and have been thinking about this. Considering adding a namespace fixed your issue, perhaps it's also something to do with the compiler settings in: Admin > Setup > Templates > Edit Template: "template-name")... in the 'Files' tab. I had a different problem with this myself and had to choose 'Auto (compile when file has no namespace)'. Worth a look anyway.
-
I updated the function now
-
Needed to add a bit more in order not to have the homepage constantly having a 'current-parent' class regardless of which page you're on: // _func.php elseif (wire('page')->parents->has($item) && !($item->id == 1)) { $str .= "<li class=\"current-parent\">"; } // crude testing in main.css .current a { color: red; } .current-parent a { color: yellow; } Works great
-
I've read about this, but I would only want to use a module once I know how to do this manually. It would save time of course, but now I've learnt about '$a->has('selector')'. Spot on! Thanks to you and @gebeer. Complete function works now as follows (with parent page class added): /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu($items, $menuClassName) { // if we were given a single Page rather than a group of them, we'll pretend they // gave us a group of them (a group/array of 1) if($items instanceof Page) { $items = array($items); } $str = ''; foreach ($items as $item) { // checkbox on page template, fieldname 'showInMenu' if ($item->showInMenu == true) { $menuText = $item->get('menuLinkTitle|title'); if ($item->id == wire('page')->id) { $str .= "<li class=\"current\">"; } elseif (wire('page')->parents->has($item) && !($item->id == 1)) { $str .= "<li class=\"current-parent\">"; } else { $str .= '<li>'; } $str .= "<a href=\"$item->url\">$menuText</a></li>"; } } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul class=\"$menuClassName\">$str</ul>"; } return $str; }
-
I'm having a little difficulty implementing a parent class on my two menus. Structure like so: Home - Link 1 -- Link 1.1 -- Link 1.2 - Link 2 -- Link 2.1 -- Link 2.2 - Link 3 The main menu displays the top level items, if the top level items has children, they are displayed in the sub-menu. I have a function like this: /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu($items, $menuClassName) { $str = ''; foreach ($items as $item) { if ($item->showInMenu == true) { $menuText = $item->get('menuLinkTitle|title'); if ($item->id == wire('page')->id) { $str .= "<li class=\"current\">"; } else { $str .= '<li>'; } $str .= "<a href=\"$item->url\">$menuText</a></li>"; } } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul class=\"$menuClassName\">$str</ul>"; } return $str; } All pages are routed through main, so in main.php, I have this to render the two menus. <!-- main navigation --> <nav> <?php $arr = $home->and($home->children); echo renderMenu($arr, 'main-menu'); ?> </nav> <!-- sub navigation --> <nav> <?php $className = 'sub-menu'; // if current page is not home if (!($page->id == 1)) { // if current page has children if ($page->numChildren > 0) { echo renderMenu($page->children, $className); } // if on a child page, still show sub-menu if (count($page->parents) > 1) { echo renderMenu($page->parent->children, $className); } } ?> </nav> What I want to do, is when, for example, on 'Link 1.1' or 'Link 1.2' page, a parent class is added on Link 1. This only affects the top menu. I was thinking along the lines of, if on 'Link 1.1' page, the current pages' rootParent (Link 1) would have the same id as the id of one of the items (its parent) of the array passed in to the function, if that makes any sense at all. Like: // this is passed in $arr = $home->and($home->children); echo renderMenu($arr, 'main-menu'); // in renderMenu() // add parent class if ($item->id == wire('page')->rootParent->id) { $str .= "<li class=\"current-parent\">"; } // add current class if ($item->id == wire('page')->id) { $str .= "<li class=\"current\">"; } else { $str .= '<li>'; } No luck so far though, and not sure where this would fit into my function. The furthest I got was getting a 'parent-page' class onto the main menu, but then the homepage was also 'parent-class' when on 'Link 1', 'Link 2' etc.. because they all share home as parent page. In another attempt, a link item would end up with 'current' and 'current-parent' at the same time. Not sure whether (a) this should be a nested if/else, or maybe a if/elseif/else or (b) if I've even used the correct selectors to get the parent page. Logic fail basically. Any help would be most appreciated. Thanks.
-
I'm only new to this too, but at a total guess: 1) Does this happen when you turn caching off and load the site? 2) Is 'stripTags()' a built in function (part of $sanitizer) and you're redefining it in your functions file? 3) Is the functions file only included once, and not somewhere else as well in another template? If '_init.php' (or whatever you've called it) is appended to your site, the functions within your '_functions.inc' file will already be available to all your other templates. // _init.php // Include shared functions include_once("./_func.php"); 4) What happens if you remove 'stripTags()' from your '_functions.inc' and then try and call this function in another template i.e. in home.php? Does the function still work? I might be well off track but I'm sure the more experienced members will have a better idea. However, these are the avenues I'd try if you haven't already.
-
Thanks. This might come in handy.
-
Thanks for all the replies, it's really helpful to a beginner. I think each to their own. If there's no team involved, I don't think it matters. Personally, this is what I am enjoying most about PW. Coming mainly from Drupal 7, the ability to just add fields, create a template, and use an API to manually spit the data out onto a webpage anywhere I want, with the markup I want is rather liberating. I don't have separate 'header.inc' and 'footer.inc' files, they never usually change so I keep the whole lot in main.php, just change the middle content section. This sounds quite interesting to me also but I'm not sure I understand what you mean by pass in $page to wireRenderFile e.g., $page->foo = 'bar'? Say I have this: // _init.php $home = $pages->get('/'); $title = $page->get('headline|title'); $content = $page->body; $summary = $page->summary; $viewBag = array( 'home' => $home, 'title' => $title, 'content' => $content, 'summary' => $summary ); $page->foo = 'bar' // where would this fit in? // main.php <?php echo wireRenderFile($page->template->name .'.inc', $viewBag); ?>
-
Apologies for quoting this again but there's something that's been bugging me. What's the point of using this method? I see structures like this when looking at MVC patterns for processwire: /templates/ -main.php (master template) -home.php -basic-page.php --/views/ ---home-view.php ---basic-page-view.php But why use the wireRenderFile() function at all? What's the advantage of having a '$viewBag' array in '_init.php' and then having to pass this around to various templates. From what I read, the idea is that the main logic would go in home.php and the HTML and basic logic would be more for home-view.php. However, what I've found that I'm struggling to see how to separate these things out. For example I have the following which outputs a basic page rendering the title/body/summary and a section underneath rendering the child pages title/summary: // _func.php function showChildPagesSummary() { $str = ''; foreach(wire('page')->children as $item) { if($item->summary) { $str .= "<div class=\"section\">"; $str .= "<h3><a href=\"$item->url\">$item->title</a></h3>"; $str .= $item->summary; $str .= "</div>"; } } return $str; } // basic-page.inc <?php if ($summary) { echo $summary; } echo $content; if (showChildPagesSummary()) { echo "<h2>In this section</h2>"; echo showChildPagesSummary(); } //main.php <!-- main content --> <div id="content"> <h1><?php echo $title; ?></h1> <?php include($page->template->name.'.inc'); ?> </div> Why not just use include() like above which has access to the custom variables in the first place (in '_init.php')? So I read over https://medium.com/@clsource/the-wire-render-pattern-806bf6d6097a#.3rpw6z6sq a few times and it looks to be abstracting away from functionality that's baked in already. I guess I just can't see a real world example where using views makes more sense (and wireRenderFile() along with custom variables passed as an array) rather than plain old include(). Any ideas would be appreciated. Thanks.
-
Thanks for the info.
-
I tried this method but found my defaults set in '_init.php' would be undefined when the page loaded. LIke this: // _init.php - prepended to current page template, i.e. main.php $content = $page->body; $summary = $page->summary; // main.php <?php //include($page->template->name.'.inc'); //works fine echo wireRenderFile($page->template->name .'.inc'); // 'Notice: Undefined variable: 'summary' ?> // basic-page.inc (template in admin alternate name = "main.php") <?php if ($summary) { echo $summary; } echo $content; Still not 100% sure why this happens.
-
Ah, welcome back sanity! Spot on thanks Adrian. Mine was set to 'Yes (template file only)'. Had no idea what this section actually did, now I have a better idea.
-
If I put this in main.php: <nav> <?php function renderMenu(PageArray $items, $menuClassName) { $str = ''; foreach ($items as $item) { $menuText = $item->get('menuLinkTitle|title'); if ($item->id == wire('page')->id) { $str .= '<li class="current">'; } else { $str .= '<li>'; } $str .= "<a href=\"$item->url\">$menuText</a></li>"; } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul class=\"$menuClassName\">$str</ul>"; } return $str; } $arr = $pages->get('/')->and($pages->get('/')->children); echo renderMenu($arr, 'main-menu'); ?> </nav> Ignore the terrible formatting, just copied and pasted it in there! So, with this, it works on all pages.
-
Thanks for the info. The only file with something similar is admin.php which has '<?php namespace ProcessWire;' at the top. I deleted everything out of '/sites/assets/cache/FileCompiler/' (if this is the correct way??). Problem still persists though. Been searching through the API and the code seems correct, but obviously something is wrong.
-
Been at this for awhile but can't work out why this issue is happening. I use main.php as my 'alternate template name' on both home and basic-page templates. The function is here (from _func.php): /** * Render navigation from array of pages * * @param PageArray $items * @param $menuClassName * @return string * */ function renderMenu(PageArray $items, $menuClassName) { $str = ''; foreach ($items as $item) { $menuText = $item->get('menuLinkTitle|title'); if ($item->id == wire('page')->id) { $str .= '<li class="current">'; } else { $str .= '<li>'; } $str .= "<a href=\"$item->url\">$menuText</a></li>"; } // if output was generated above, wrap it in a <ul> if ($str) { $str = "<ul class=\"$menuClassName\">$str</ul>"; } return $str; } ...and I call it in main.php thus: <!-- main navigation --> <nav> <?php echo renderMenu($pages->get('/')->and($pages->get('/')->children), "main-menu"); ?> </nav> So, when on a page created with a basic-page template, for example, 'About', at mysite.com/about/ the menu works fine. Shows 'Home | About | Contact'. However, when I now go to the homepage, it's error time! Fatal error: Uncaught TypeError: Argument 1 passed to renderMenu() must be an instance of PageArray, instance of ProcessWire\PageArray given, called in /Users/Sam/dev/ecoop.dev/site/assets/cache/FileCompiler/site/templates/main.php on line 28 and defined in /Users/Sam/dev/ecoop.dev/site/templates/_func.php:10 Stack trace: #0 (this is just the first couple of lines). Ok, so I echo out a bunch of stuff, like: echo $pages->get('/')->and($pages->get('/')->children); // returns 1|1015|1018|1019|1022 on EVERY page including HOME All I wanted to do was to pass this array into the function, and print the menu on every page. My PHP 'skills' are limited you will no doubt see. Basically, I'm lost! Any help is much appreciated. My main confusion is why doesn't this code work on the homepage, but works on every other page? Thanks.
-
I like the sound of this! Gonna give it a try, thanks for sharing.
-
Thanks for the info. I wondered if the function expected an array, why not: function renderNav(array $items) { ...but now I see 'PageArray' here: https://processwire.com/api/arrays/page/ And I'm guessing: if($items instanceof Page) $items = array($items); ...refers to an object which is an instance of a class named 'Page': https://processwire.com/apigen/class-Page.html Makes more sense now (if I'm correct that is). Thanks.
-
Hi, Been away for awhile focussing on javascript but need to actually make a site now and was impressed with processwire a few months back when I was messing about with it. So I've cleverly started with a blank site with the hope that I can learn a lot more than starting with a half built one. I'm looking at the example functions in _func.php (from my previous site, my current _func.php is blank of course) and have a question about the functions: function renderNav(PageArray $items) { Why is 'PageArray' in there? Is that just to make one aware that this argument wants an array? Or does it do something else? Bear in mind PHP isn't what I'd call my strong point. and function renderNavTree($items, $maxDepth = 0, $fieldNames = '', $class = 'nav') { // if we were given a single Page rather than a group of them, we'll pretend they // gave us a group of them (a group/array of 1) if($items instanceof Page) $items = array($items); Same here with '$items instanceof Page)'. Never seen anything like it, is it a PHP thing or a built-in processwire thing? I'm hitting up the cheatsheet and echoing out a load of built-in field references to see what they return whilst on various pages before I actually try and build a simple 1st level navigation, then a second submenu which lists child pages of the current parent page (which also stays visible when on the child pages themselves). I don't really want to use a module as it would teach me nothing. Anyway, going off subject here, the menu is for another thread when I undoubtedly get stuck. Thanks for any advice.
-
Yes, of course, nice! Haven't got into taxonomy yet but the powers of PW are revealing themselves in a most pleasing way. Everything so far seems quite sensible with no outrageously complicated abstractions (looking at you Drupal 7).