Jump to content

Search the Community

Showing results for tags 'snippets'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development


There are no results to display.

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL







Found 4 results

  1. Just wondering what software/approaches others take to the management of their code snippets. Relatively new to PW and finding that its logical approach is making it far easier for me to reuse code in projects and encourages me to try and be more organised! I've looked at few notes apps that piggyback of Gists - although I'm not sure if Gists is a good idea for private project work seeing as they're never totally private.
  2. I was struggling a bit getting all subfields of a field if type is unknown. I made a small function for use in templates which returns an array() of all properties of (maybe any?) pagefieldvalue. If there is something similar in core (which I couldn't find) please let me know. Tested it with Fiedtype Options, Page, ProfieldsTable. Feel free to use it. /** * ProcessWire UsefulSnippets * * How to get all properties, subfields of any field if you don't know the type only if value is set * @return array */ function getProperties($fieldvalue) { // multiple value field if ($fieldvalue instanceof WireArray) { $result = array(); foreach ($fieldvalue as $subfieldvalue) { $result[] = getProperties($subfieldvalue); } return $result; // single value field with subfields } else if ($fieldvalue instanceof WireData) return get_object_vars($fieldvalue->getIterator()); // single value field else return $fieldvalue; } // Example var_dump(getProperties($page->myfield));
  3. Hello everyone. I thought I'd share a few of the functions I've been working on in case any new users etc find them useful. I've not been programming in PHP long, so excuse the sloppy code, and if you find any errors etc, let me know and I will update it. The following function basically takes your $page date and returns it in either hours and minutes if the page is less than a day old, or as sandard if it's older. This could also be extended to display the date as yesterday etc as well. If people are interested, I can add more, and feel free to add your own. function formatDate($itemDate) { // Let's check the item date against the current date so that we can work out the date and time difference. $itemDateTime = new DateTime($itemDate); $currentDateTime = new DateTime('now'); $interval = $itemDateTime->diff($currentDateTime); $day = $interval->format('%d'); $hour = $interval->format('%h'); $minute = $interval->format('%i'); // If it's less than a day, display the date as hours and minutes since the post. // $day == 0 means there is no day difference, i.e we know it is on the same day. if($hour < 24 && $day == 0){ // If it's been less than an hour. if($hour < 1){ if($minute == 0){ $itemDate = "less than a minute ago"; } elseif($minute == 1){ $itemDate = $minute . " minute ago"; } else{ $itemDate = $minute . " minutes ago"; } } // If it's been more than an hour and less than a day. elseif($hour >= 1 && $hour < 24){ if($hour == 1 && $minute == 0){ $itemDate = $hour . " hour ago"; } elseif($hour == 1 && $minute == 1){ $itemDate = $hour . " hour and " . $minute . " minute ago"; } elseif($hour == 1 && $minute > 1){ $itemDate = $hour . " hour and " . $minute . " minutes ago"; } elseif($hour > 1 && $minute == 0){ $itemDate = $hour . " hours ago"; } elseif($hour > 1 && $minute == 1){ $itemDate = $hour . " hours and " . $minute . " minute ago"; } elseif($hour > 1 && $minute > 1){ $itemDate = $hour . " hours and " . $minute . " minutes ago"; } } } // If it's more than a day, just post the standard date. else { $itemDate = $itemDate; } return $itemDate; } The following function can be used in conjunction with the formatDate($itemDate) above. /* This function outputs each article / page header according to how we want it. ** $icon = Font Awesome icon etc, i.e "fa fa-link" which could be used if we create a links system. ** $item = Usually the $page we call the function from. ** $type = A string in the form of Article, Link etc. ** Example: If we call the function with the following args showItemHeader("fa fa-link", $link, "Link"); ** We will see the following displayed: (link icon) Link published 22 hours ago in Website Links ** Obviously change the markup to suit your own needs. */ function showItemHeader($icon, $item, $type) { echo "<h3><a href='{$item->url}'>{$item->title}</a></h3>" . "<h6><i class='$icon'></i> " . $type . " published: " . formatDate($item->date) . " in " . "<a href='{$item->parent->url}'>{$item->parent->title}</a></h6>"; }
  4. Hi all, I'm a big fan of the Sublime Text 2 text editor and of course of huge fan of ProcessWire, so I went ahead and created a library of PW snippets to be used with the ST2 Snippet system. I followed the PW cheat sheet, and created Advanced and Basic versions. The Advanced version contains only those seen in the advanced mode of the cheat sheet, so if you want the full set, you'll want to get both Basic and Advanced. They are on GitHub here: https://github.com/evanmcd/SublimeProcessWireSnippetsBasic https://github.com/evanmcd/SublimeProcessWireSnippetsAdvanced I've just submitted the Advanced set for inclusion into Package Manager, so hopefully that will be added soon. See the README for more info. Any feedback welcomed
  • Create New...