Jump to content

SamC

Members
  • Posts

    733
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by SamC

  1. I wonder how much overhead? What is considered 'large amounts of markup' as quoted from your link? Your second point is interesting. If this approach is easy for web designers (or developers) to understand, this may help in the convincing of clients that anyone would be able to take over the site in the future because the template structure is so intuitive/straight forward.
  2. I just made a copy of my templates folder, renamed the copy 'templates.delegate' and now in the process of trying out the new markup regions to see how it suits me. Thanks for the newer link @bernhard Having: <region id="main"></region> replaced by: <section id="main"> <h1>Welcome to my website!</h1> <p>This is the awesome text of my awesome website</p> </section> (EDIT - the section tags are not printed) reminds me a bit of extending in twig, where you could: // master template <div id="content">{% block content %}{% endblock %}</div> and then in the child template: {% extends "base.html" %} {% block content %} <h1>Index</h1> <p class="important"> Welcome on my awesome homepage. </p> {% endblock %} Not paid a great deal of attention to this approach but I like the look of it.
  3. I have used this approach for the past 4 sites. Now I'm considering other options though. Things like this though... <?php $headline = $page->get("headline|title"); // bodycopy is body text plus comments $bodycopy = $page->body . $page->comments->render(); $sidebar = $page->sidebar; // check if this page has any children if(count($page->children)) { // render sub-navigation in sidebar $sidebar .= "<ul class='nav'>"; foreach($page->children as $child) { $sidebar .= "<li><a href='$child->url'>$child->title</a></li>"; } $sidebar .= "</ul>"; } include("./main.inc"); ...makes me think a few things: 1) Having to make strings out of all my HTML is a royal pita. 2) No autocomplete for HTML tags in ST3 when pretty much everything is chucked into strings. 3) However, this is easier to read than some of the the alternate syntax I'm using i.e. when there's a bunch of if/else, inside a loop, maybe a second loop, then the alternate syntax I also find a pita. 4) I like the idea of being able to pre-populate things, then just render them out later depending on which template is loaded. Makes a fair bit of sense. So, it seems I'm unpleasable good news is, whatever approach you take @Violet you've got a forum full of incredible help here.
  4. Ha, I never noticed that either. Corrected my example. Gonna try this in tracy too, nice tip. @szabesz what extras does wiremailsmtp module bring compared to my approach above?
  5. I never got it working on localhost either tbh. Did it on a subdomain on a live server.
  6. Not sure what you mean here. Do both templates have this field called 'tags'? Is a page reference field I presume.
  7. I think you're nearly there. I'll have a stab at this and maybe, if you take code B, and add to it: <?php // wrap the whole thing in a condition that only runs // if the form has actually been submitted if ($input->post->submit) { // get the values submitted from the form via the 'name' attribute on each input field, // pass them through sanitization (to remove any possible malicious code), // and save to variables $name = $sanitizer->text($input->post->name); $userEmail = $sanitizer->email($input->post->email); $comments = $sanitizer->text($input->post->comments); $subject = "Feedback from my site"; $myEmail = "me@me.com"; // construct the email body content that you'll receive $emailContent = " <html> <body> <p><b>Name:</b> {$name}</p> <p><b>Email:</b> {$userEmail}</p> <p><b>Comments:</b></p> <p>{$comments}</p> </body> </html> "; // create new wireMail object $mail = wireMail(); $mail->to($myEmail)->from($userEmail); $mail->subject($subject); $mail->bodyHTML($emailContent); $mail->send(); } ?> It would replace your Code A. I'm not as experienced as the other members here but I think something like this. =EDIT= You'll want some kind of validation though because this would run even if the fields weren't all filled out. This is what... wireIncludeFile("./vendor/vlucas/valitron/src/Valitron/Validator.php"); $v = new \Valitron\Validator(array( "name" => $name, "email" => $email, "message" => $message ) ); $v->rule("required", ["name", "email", "message"]); $v->rule("email", "email"); ...from my original link does. Makes sure the required fields are not empty. Worry about that once the form works though
  8. Not 100% sure, let me test... when I remove the namespace from one of my includes I get... Fatal error: Uncaught Error: Call to undefined function renderTags() What I do (maybe unnecessarily) is just paste that line at the top of every template. it fixes my errors anyway. I believe it's to do with the compiling of the files Admin > Setup > Templates > Files (tab) and using 3rd party PHP libraries so variables don't collide. I'm no PHP expert so don't quote me on this! I'm thinking of going this way myself, or at least the new template strategy. Things are getting a little weird with includes, especially my header which changes depending on what template is loaded. Got some funky logic in an include file right now that just doesn't feel right. What puts me off is all the HTML in strings in terms of syntax autocomplete/highlighting in ST3.
  9. Hi @Violet This should work fine. What I'd do is make the path: /site/templates/includes/displaylist.php and link to it with: <?php include(".includes/displaylist.php"); ?> Do you need an include file though? I mean, is it that big or complex? If the list is just the linked titles, you could (not tested): <aside> <h3>Three Random Posts</h3> <!-- get the list, then display it --> <?php // can chain the methods, first part returns an array with all pages // created with 'my-post'. Second part, gets random x 3 from first array // and returns a new array, which is then shuffled and saved to $itempages $itempages = $pages->find("template=my-post")->getRandom(3)->shuffle(); // if items are actually returned if (count($itempages)): ?> <ul> <?php // loop over them foreach ($itempages as $itempage): ?> <h4><?= $itempage->title; ?></h4> <?php endforeach; ?> </ul> <?php else: ?> <p>No posts found :(</p> <?php endif; ?> </aside> ...or you could do it with an include: <aside> <h3>Three Random Posts</h3> <!-- get the list, then display it --> <?php // can chain the methods, first part returns an array with all pages // created with 'my-post'. Second part, gets random x 3 from first array // and returns a new array, which is then shuffled and saved to $itempages $itempages = $pages->find("template=my-post")->getRandom(3)->shuffle(); // if items are actually returned if (count($itempages)): ?> <ul> <?php // loop over them foreach ($itempages as $itempage): ?> <?php include("./includes/displaylist") ;?> <?php endforeach; ?> </ul> <?php else: ?> <p>No posts found :(</p> <?php endif; ?> </aside> and displaylist.php like: <?php namespace ProcessWire; // caveat being that the variable MUST be called '$itempage' here ?> <h4><?= $itempage->title; ?></h4> <?= $itempage->summary; ?> <?= $itempage->whatever; ?> It's up to you really ==EDIT== I am unsure by your example if you need different fields from each page $itempagezero, $itempage1 and $itempage2. Would need to see the contents of INC_displaylist.php. You did mention 'all templates will display an identically-formatted list of 3.'. ==EDIT 2== Can I just clarify something. You can also use wireIncludeFile() function which is awesomer (is that a word?) than the standard include because you can pass variables INTO the template. The standard include above is simply used 'as if it were typed directly into the containing template'. This is just another approach. <aside> <h3>Three Random Posts</h3> <?php $itempages = $pages->find("template=my-post")->getRandom(3)->shuffle(); if (count($itempages)) { // include the file and pass the pages into it wireIncludeFile("./includes/displayist.php", array('mypages' => $itempages)); } ?> <h3>Newest 5 Posts</h3> <?php $itempages = $pages->find("template=my-post, limit=5, sort=created"); if (count($itempages)) { // include the file and pass the pages into it wireIncludeFile("./includes/displayist.php", array('mypages' => $itempages)); } ?> </aside> and displaylist.php <?php namespace ProcessWire; ?> <ul> <?php // loop over the value/s of the 'mypages' array key foreach ($mypages as $itempage): ?> <li><a href="<?= $itempage->url; ?>"><?= $itempage->title; ?></a></li> <?php endforeach; ?> </ul> There's just so many ways. I haven't tested this one either but you get the idea. You can see why people here (and myself) love the flexibility processwire provides! you can arrange your templates any way you want, whatever makes sense to you.
  10. Ah. I saw that one and didn't install because of 'under development'. Teach me for being a coward. Thanks. Good video btw ?
  11. Not tried this one, added to the huge todo list ?
  12. No probs, glad to help. Also see this one: ...which might be useful in addition to the other one.
  13. Hi @ryanC Not sure whether you've seen this: Also, not sure how to exactly help with your approach but the above worked very well for me so far. Includes recaptcha and validation.
  14. I saw a video on youtube: https://www.youtube.com/watch?v=T93nn96UL8o I'm getting a large list right now because I'm using a repeater matrix with 20+ fields on each page (image > body > image > body > code > body > image etc...) so when I save after editing a bunch of fields (without saving in-between) it literally takes up my whole screen. Using AOS I can press the delete key but any way to make these a little more subtle? I think there may have been a thread on here a while back but I can't find it where someone mentioned something similar and how they handle these notices. I can't find anything googling for stuff like 'processwire hiding session messages' or 'processwire alternate session messages'. Like the notices in this: https://processwire.com/talk/topic/15047-show-notices-in-processwire-modal/?do=findComment&comment=135009 Any ideas would be appreciated, thanks.
  15. Once you add your the tag, it can take 24-48hrs for any results to be seen in the analytics account so you wont know if this is working or not for at least a day. This is a good suggestion, especially if you're going to change it out for a wordpress site anyway.
  16. Thanks, sure something like this will be useful.
  17. This is an awesome thread! Thanks all. @flydev can I ask how you created the animation in your first post? Something like this might be useful in my tutorials rather than tonnes of images.
  18. ==UPDATE== I did this in the end using a single 'blog-entry' template. I have the structure: post 1 post 2 post 3 - post 3.1 - post 3.2 post 4 post 5 My menu is now in an include file: <?php namespace ProcessWire; ?> <?php // check if menu needs to be rendered before getting PageArrays if ($page->template == "blog-entry" && $page->parent->template == "blog-entry" || $page->template == "blog-entry" && $page->hasChildren()): // children of complete-guice parent if ($page->template == "blog-entry" && $page->hasChildren()) { $entries = $page->and($page->children); } // children of complete-guide parent elseif ($page->parent->template == "blog-entry") { $entries = $page->parent->and($page->parent->children); } ?> <ul class="list-group"> <?php foreach($entries as $index => $entry): // apply 'active' for current page $currentClass = ($page->id == $entry->id) ? "active" : ""; // change the parent blog post page title to 'Summary' $title = ($index == 0) ? "Summary" : $entry->title; ?> <li class="list-group-item <?= $currentClass; ?>">Page <?= $index + 1; ?>:&nbsp;<a href="<?= $entry->url; ?>"><?= $title; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> ...and to output it at the top of a blog post. Only shows if the page has children: // blog-entry.php <?php namespace ProcessWire; ?> <?php include("./includes/multi-page-menu" . ".php"); ?> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-lg-9"> <?php if($page->bodyRepeater): ?> <?= $page->render("bodyRepeater"); ?> <?php endif; ?> </div> </div> </div> <?php include("./includes/multi-page-menu" . ".php"); ?> ...with structure: ...renders: Only need one template now for anything that is a blog post whether it's a single page or has children. Now I can use the family settings properly without having to choose a template when Adding New > Blog Post. I'm quite a big fan of these settings.
  19. Module works amazing. In my case, I needed to show the fields only if the page does not have a parent of a certain template (as the child pages simply display the parents fields on the webpage), selector: parent.template!=complete-guide ...and the out the box options only allows for fields on the same page. Thanks @Robin S
  20. @adrian I think it might take awhile to get used to but I'll give it a shot.
  21. One of those times that even though I'm pretty pleased with my progress, a quick scroll in there tells me I've only just got over a few small rocks at the bottom of the massive PHP mountain. Do you leave this on when a site goes live or uninstall it?
  22. Been meaning to do it for awhile, this reminded me. Gonna go and install her now.
  23. SamC

    video upload

    Nice! Will bookmark this one for a later date
  24. @houseofdeadleg weird! I'm pretty intrigued with this. Gonna go try pagination right now on my test site. =EDIT= Ok, just did it and works ok. <?php namespace ProcessWire; ?> <?php // template file blog-index.php // make sure to set pagination on the template that lists the pages, // not on the template of the individual items that are being listed // i.e. in your case, on template 'news' ?> <?php // get top level posts only under /tutorials/ $entries = $pages->find("template=blog-entry|complete-guide, sort=-postDate, parent=1017, limit=6"); $pagination = $entries->renderPager(); ?> <div class="container py-5"> <?= $pagination; ?> </div> <div class="container py-5"> <div class="row"> <?php foreach ($entries as $entry): ?> <div class="col-md-4 mb-5"> <?php include("./includes/card" . ".php"); ?> </div> <?php endforeach; ?> </div> </div> ...outputs: <ul class='MarkupPagerNav' role='navigation' aria-label='Pagination links'> <li aria-label='Page 1, current page' class='MarkupPagerNavOn MarkupPagerNavFirst MarkupPagerNavFirstNum' aria-current='true'><a href='/processwire-tutorials/'><span>1</span></a></li> <li aria-label='Page 2'><a href='/processwire-tutorials/page2/'><span>2</span></a></li> <li aria-label='Page 3' class='MarkupPagerNavLastNum'><a href='/processwire-tutorials/page3/'><span>3</span></a></li> <li aria-label='Next page' class='MarkupPagerNavNext MarkupPagerNavLast'><a href='/processwire-tutorials/page2/'><span>Next</span></a></li> </ul> And on screen, just a basic list: Pretty confused at why yours don't click.
  25. What happens if you just render it like in the PW docs example? <?php $results = $pages->get("template=news")->children("limit=10, template=news_item, category.title=education, sort=-date, include=hidden"); $pagination = $results->renderPager(); echo "<ul>"; foreach($results as $result) { echo "<li><a href='{$result->url}'>{$result->title}</a></li>"; } echo "</ul>"; echo $pagination;
×
×
  • Create New...