Jump to content

Leaderboard

Popular Content

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

  1. Hi, This issue is partially discussed over here:
    4 points
  2. You have to perform the check for the template name inside your hook function. $this->page or wire('page') returns whatever page in which the module code is executed (admin page editor, custom page with the code...). Pages::save on the other hand is called with the page object being saved, which is what you're looking for. public function init() { $this->pages->addHookAfter('Pages::save', $this, 'syncMobileDE'); } protected function syncMobileDE(HookEvent $event) { $page = $event->arguments(0); if($page->template->name == 'TemplateName') { // Run your code } }
    4 points
  3. You mean @horst's Image Animated GIF module? Compatibility is set to 2.5, 2.6, 2.7, 3.0, so maybe that's why?
    3 points
  4. This has now been updated and works on PW3. I've also added download hit tracking so at least you have a small amount of stats on file downloads for your podcast. I've also added some readme text https://github.com/benbyford/pw-podcast
    2 points
  5. I think this may be your problem: https://processwire.com/api/selectors/
    2 points
  6. You can also do $f = new Field(); $f->setArray([ 'name' => 'field_label', 'type' => wire('modules')->get('FieldtypeWhatever'), 'tags' => 'tag1 tag2', 'label' => 'Field Label', 'columnWidth' => 50, ] );
    2 points
  7. To create a sitemap.xml you can use Pete's Sitemap XML module, or you can create a template file and page to do it for you. This post explains how to create a template to do it for you. The benefit here is that you may find it simpler to tweak a template file than a module, though either is a good solution. Here is how to do it with a template file and a page: sitemap-xml.php <?php namespace ProcessWire; /** * ProcessWire Template to power a sitemap.xml * * 1. Copy this file to /site/templates/sitemap-xml.php * 2. Add the new template from the admin. * Under the "URLs" section, set it to NOT use trailing slashes. * 3. Create a new page at the root level, use your sitemap-xml template * and name the page "sitemap.xml". * * Note: hidden pages (and their children) are excluded from the sitemap. * If you have hidden pages that you want to be included, you can do so * by specifying the ID or path to them in an array sent to the * renderSiteMapXML() method at the bottom of this file. For instance: * * echo renderSiteMapXML(array('/hidden/page/', '/another/hidden/page/')); * */ function renderSitemapPage(Page $page) { return "\n<url>" . "\n\t<loc>" . $page->httpUrl . "</loc>" . "\n\t<lastmod>" . date("Y-m-d", $page->modified) . "</lastmod>" . "\n</url>"; } function renderSitemapChildren(Page $page) { $out = ''; $newParents = new PageArray(); $children = $page->children; foreach($children as $child) { $out .= renderSitemapPage($child); if($child->numChildren) $newParents->add($child); else wire('pages')->uncache($child); } foreach($newParents as $newParent) { $out .= renderSitemapChildren($newParent); wire('pages')->uncache($newParent); } return $out; } function renderSitemapXML(array $paths = array()) { $out = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; array_unshift($paths, '/'); // prepend homepage foreach($paths as $path) { $page = wire('pages')->get($path); if(!$page->id) continue; $out .= renderSitemapPage($page); if($page->numChildren) $out .= renderSitemapChildren($page); } $out .= "\n</urlset>"; return $out; } header("Content-Type: text/xml"); echo renderSitemapXML(); // If you want to include other hidden pages: // echo renderSitemapXML(array('/path/to/hidden/page/'));
    1 point
  8. Hi, I have created a site profile that shows how to integrate ProcessWire 3.0 with Vue 2.0. See repository here. How this site profile works This ProcessWire site profile is loosely based on the REST API tutorial by @gebeer. Here are the most important steps to reproduce it: Admin settings Create an api template with default settings and just the title field assigned to it. Refer to @gebeer tutorial for further details Create a pages and nav templates with just the title field, for both template tick “Allow URL Segments” in the “URLs” tab (see attachment) Create a home template, this is going to be the single php file that will load your Vue SPA. Assign this template to the root of your website Any other template you create should have the “Alternate Template Filename” field in the “Files” tab set as home (see attachment), in this way if a user enter the website from any url that is not the root, ProcessWire will always redirect to the home template, Vue router will handle the url and call the right data through the REST API Under the root, create an api page and assign the api template to it (you can set “hidden” to this page so doesn't show up in the menu) Under the api page, create the pages nav and pages (see attachment), and assign the templates nav and pages to them. Now you have the www.sitename.com/api/pages and www.sitename.com/api/nav urls that you can use to fetch the JSON data PHP template setup In the templates folder, create home.php file and leave it empty, the HTML will be generated by webpack Now create pages.php and nav.php files. On these files is where we return the JSON data, based on the right url segment. Again, refer to @gebeer tutorial for further details on this matter. Note that I wrote a PageFields class that I use on these templates to fetch ProcessWire fields. The fields that are supported are text, textarea, repeater, img. Other fields may work but I haven't tested them. See the REST API setup for further details about how to use the PageFields class REST API setup You can decide what fields are included and what fields are excluded by passing a configuration array to the PageFields class. You can find here a list of the available configuration settings. See examples below. Show only selected core fields: $pageFields = new PageFields($p, [ 'fld_core_included' => ['url', 'httpUrl', 'template'] ]); Show no global fields, and only selected custom fields: $pageFields = new PageFields($p, [ 'fld_core_included' => [], 'fld_include_all' => false, 'fld_included' => ['title', 'gallery'], ]); On a gallery image field, hide breakpoint listing and show only httpUrl field: $pageFields = new PageFields($p, [ 'img_fld_overrides' => [ 'gallery' => [ 'fields' => ['httpUrl'], 'bp_list' => false ] ], ]); Webpack setup The most important file of all Webpack setup is config/index.js. On line 33 you need to provide your domain name so that Webpack can proxy the ProcessWire REST API to the Webpack dev server. Without this you wouldn't be able to take advandage of the Webpack hot module replacement feature which allows you to reload a vue module without refreshing the page, it also allows you to keep the state of the app. Notes My REST API may have bugs, this is just an example of an integration with ProcessWire, I suggest you either build your own REST API or use the awesome GraphQL module by @Nurguly Ashyrov. Todo Replace REST API with the GraphQL module. This requires vue-apollo, the Apollo/GraphQL integration with Vue, and vue-supply for integration with Vuex.
    1 point
  9. Looking to write a tricks and tips article, anyone got anything which is SUPER useful for Processwire users which sits outside of installation and general usage and structure? Maybe things you wish you were told, or little tricks to get around restrictions or issues.
    1 point
  10. Here is the scenario. You have developed a blog or news site or blog section to your site and you have created a basic tag system using a Page Reference field. How can you add related articles easily? This is one way by using Hanna code. I like this method because it gives me the choice of showing or not showing related articles and choosing the tag. My articles use a template called basic-page which includes a Page Reference field called tags. This is a multiple select field. I have created a Hanna code called "tagsearch" and given it the attribute "tag". In my textarea field it is used thus: [[tagsearch tag="fish"]] The Hanna code simply searches the title field of the tags pages for the single term and returns the pages that have that tag. I have limited the results to 8. From the results, we pluck the title field of the pages, the small image that I use for my thumbnail, and the url. However, we do not want to also return the page we are displaying, so we simply eliminate it by making sure that that none of the results have the same page name. Here is the commented Hanna code. <?php // Find the pages that use the specified tag $articles = $pages->find("template=basic-page, tags.title=$tag, limit=8"); // Start the loop foreach($articles as $article){ // Check we are only displaying articles that are NOT the current page if($article->name != $page->name){ // Add a thumbnail, but check it is there so we don't get errors if($article->image_small){ echo "<a href='{$article->url}'><img src='{$article->image_small->url}'></a><br>"; } // Grab the article title echo "<br><a href='{$article->url}'>{$article->title}</a>"; // end the check to make sure we do not show the current page } // end the loop } And that is it.
    1 point
  11. Hi @benbyf I cannot come up with something that has not been addressed in the forums in some way or another, there is so much buried here that it is probably impossible to decide what should be highlighted more than others. It might not fit your current needs, but what I would like to see in a more concise/tutorial like manner is implementing complete frontend user features from scratch. Well, maybe not from scratch, you could use UIkit 3 to do the design stuff, but other than that only pure PW could be used, even without the backend's form API. Something like this one turned into a complete tutorial: Such a tutorial would not only provide on solution to the long standing "how to do frontend users" dilemma, but it would also be a great example of implementing forms, sending emails, etc..
    1 point
  12. You might also try conditional hooks: https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/#new-conditional-hooks
    1 point
  13. Hi @Alex L As far as I can see you need to implement your own version of "article summary" so that you have something to output instead of "body". Such as: https://processwire.com/blog/posts/pw-3.0.28/ You can also extract the first paragraph in various ways: http://stackoverflow.com/questions/8757826/i-need-to-split-text-delimited-by-paragraph-tag Hope this helps. If get stuck just post what you implement so that we can help further.
    1 point
  14. BOOOOOOOM thanks @szabesz - when tested, doens't work on PW 2.4 (but is a shared server so might be their setup) but works a charm on PW 3.0 hosted with digital ocean.
    1 point
  15. UPDATE: I couldn't find anything suspicious in the DB dump diff. So after tinkering for a while I decided to try a workaround. I added a new role and gave it the same template-level permissions as the 'faulty' role that caused the problems. Then I assigned this new role to the admin user with the old, 'faulty' role (in addition to the old one). And this helped, the JS error is now gone. Not sure, though, what to make of this. It seems to be pointing to a problem in the settings for that 'faulty' role. But I went through the role and permission settings numerous times and couldn't find anything unusual. So for now I will let it be as it is. Although I really would like to find the real cause of the problem. Just don't know where else to look for it. Feels a bit uncomfortable to have a site running in production with a strange admin error that might reappear anytime... So if anyone reading this has an idea, please let me know. But thanks for reading anyways.
    1 point
  16. Are you absolutely sure you are on the same domain after the redirect? I had some issues with redirect to subdomains.
    1 point
  17. @adrian Its only the extensions. maxFiles and outputFormat is set to 0 ((int) NULL) by default. @hellomoto No need to set inputfieldClass. The following is enough to get it work. $f = new Field; $f->name = 'myfield'; $f->type = 'FieldtypeImage'; $f->extensions = 'gif jpg jpeg png'; $f->save();
    1 point
  18. It's probably the valid extensions and missing max files settings - take a look at the Details tab of an image field. I would set those and maybe also the formatted value setting.
    1 point
  19. @tpr, another idea/request: if the "permanent delete" option for Page List is checked then there is also an option to permanently delete the page from the Delete tab of Page Edit. Thanks!
    1 point
  20. yep, that's what i forgot to recommend.
    1 point
  21. https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/#new-conditional-hooks
    1 point
  22. To add the 'country' field you can simply do this: $inputfield = $user->getInputfields('country'); $form->add($inputfield); Depending on how many fields in your user template, when building a profile edit form for the frontend it can be easier to define an array of 'ignore' fields and then add all inputfields for the user template that are not in the ignore array. Pretty sure I got this idea from some code by @Soma. // Get the fields from the user template $inputfields = $user->getInputfields(); // Don't include these fields in the form $ignore_fields = [ 'user_name', 'temp_password', 'roles,' ]; // Add the inputfields to the form foreach($inputfields as $inputfield) { if(in_array($inputfield->name, $ignore_fields)) continue; $form->add($inputfield); }
    1 point
  23. Yeah, I had my nightmares with this situation too. There are lots of scenarios when ProcessWire could redirect your ajax requests and the graphql will not receive the query. The ones that I had encountered were: If the url ends without slash: ...website.com/graphql ==> ...website.com/graphql/ If there is now www prefix: website.com/graphql/ ==> www.website.com/graphq/ And now I guess when languages are enabled you also gotta make sure ProcessWire is not redirecting you to the respective language url of the graphql api. I haven't tested the module with the languages enabled yet, but I am sure there would be some additional caveats. Yes, that's the expected behavior. Unfortunately to support permission inheritance would be too expensive. Because it means to check template permissions of each ancestor of each returned page. I think the module is already slow and supporting permission inheritance would make it even slower. I guess I have to mention about not supporting permission inheritance somewhere in the documentation of the module. That's right, it turns out there was a bug. I pushed an update regarding the datetime field. Grab the latest version of the module and it should work properly. Yep. That's the way. I know, it's ugly. But I can't think of a less verbose way to return a single page from the api. We could, of course introduce an additional field for each template like basic_page_single or something. But I don't think it's worth it, plus it will make the schema bigger for very little gain. I totally agree. We can't allow everyone to create images. The size field of the image type creates images only if the user has an edit permission on that image field. It is still available to the users who do not have edit permission, but only for getting existing variations, and it should return null if there isn't an image variation with the requested size. Edit: By the way, thanks a lot for the feedback.
    1 point
  24. Yeah, I Know.. but with PW you can do whatever you want!! lol
    1 point
  25. It's not a bug, but just how processwire does handle this kind of selector. If you need empty tags as well use the following: $pages->find("parent=/things, (tags.name!=xx), (tags=''),limit=10")
    1 point
  26. The abovementioned feature is available in v141, plus a new CKEditor plugin Indent Block and some minor updates.
    1 point
  27. Thanks @adrian! I rerecorded the video many times before I could make it watchable. Trust me, you wouldn't say the same thing for the very first ones About the field access rules. Yeah that's true. By default the behavior is the opposite to the one in ProcessWire. I think it would be better for security if the module initially treats everything private. But I get what you mean. In cases where you have dozens of fields in one template, it would be too tedious to configure access for each of them. That's why there is an option to reverse the behavior in the advanced section of the module configuration. You can learn more about it here. This option basically makes all fields without Access rules available to the public and you can restrict access by enabling rules only to couple ones.
    1 point
  28. Hi @mvdesign. So sorry that I could not respond earlier. I decided to make an introduction video for this module to help people that are trying to use it. But then, I never made a screencast video before, and on top of that, the last time I spoke english was 2011. So I had to take dozens of try-outs till I got something watchable. So here is the video. It shows how you would create/update pages with this module. The video is far from OK, so I will probably record another one after I get some feedback. Until then please refer to this video to learn about how the module works.
    1 point
  29. Handy shortcuts to edit translations in a textdomain file in other languages in the upcoming version:
    1 point
  30. The following quote from the blog post is useful in understanding how your templates need to be structured in order for Markup Regions to work: So the general rule is: the place where you define your 'original' markup regions (that you will append to, etc, in your template files) needs to have the doctype or <html> element in it, and it needs to be the last piece of markup to be rendered. That's why your markup regions would typically be originally defined in an auto-appended "_main.php" so that it is rendered last, and any markup that you are echoing or outputting in your template files will reference those regions and appear before the doctype/<html> of _main.php.
    1 point
  31. Hi @flydev, any news on the release? Thanks!
    1 point
  32. Very interesting, that CSS-Grid stuff. I'm thrilled. Here is a short list of usefull links: (must read) http://jensimmons.com/post/feb-27-2017/learn-css-grid http://gridbyexample.com/examples/ (some specs and technical info) http://gridbyexample.com/browsers/ https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/CSS_Grid_and_Progressive_Enhancement https://drafts.csswg.org/css-grid/#grid-containers (some more) https://css-tricks.com/css-grid-one-layout-multiple-ways/ PS: you also can support older browsers with different fallbacks, there are tuts over that too.
    1 point
  33. If you don't need to worry about browser support then you should take a look at the newly available css grids.
    1 point
  34. v134 has a new option for FileFieldTweaks: disable filename truncation for File fields. Thanks @BitPoet for the right track and @Robin S for the request. This was something bugged me for some time but was lazy to investigate
    1 point
  35. Hi - I'm totally not following your post. However, based on your 2nd sentence, this would be my answer: Create template called plant add 3 fields Title (default) Type: textarea; Title: Description (optionally use CK editor) Type: page reference; Title: Page Select (page_select); configure this to select the link to another page Create template called plant-index one field, title; configure the family settings to allow children of template plant configure the allow new pages to 1 Create a new page using this template Go back to plant template and family settings, no children and plant-index for allowed parent Go to the page tree and hover over the Plant Index, then 'new' - this will give you a new plant Add your title, description and select the page you want to link to, save Repeat steps 4-5, 199 more times.
    1 point
  36. New feature in v131: new move to first/last buttons for file/image fields (FileFieldTweaks). This adds up/down icons (right-left in case of images) that you can use to move items to the first or last position.
    1 point
  37. 1 point
  38. http://leafletjs.com/examples/choropleth/ Another awesome option for chloropleth maps is: http://datamaps.github.io/
    1 point
  39. @Mats @gebeer Thanks to a job I just finished for @dab I have been actively taking your work forward. I have a fork of the project here that... Simplifies getting the needed files used by MarkupLeafletMap into a template's header Integrates the Leaflet.AwesomeMarkers project and the latest FontAwesome icons into the module Adds a callback function for customising the content's of a marker's popup box Adds a callback function for customising the visual appearance of any marker Updates the readme file significantly Provides an example template file to help get folks underway with this module in their projects I based my work on gebeer's extension of your repo Mats, so I have issued a pull request to gebeer - but I'd like to get these changes into your repo if possible as then we can revert to your repo as the master codebase and, hopefully, have the latest goodies straight from the PW module directory. It's now very easy to add fields to the marker pages that let you customise their appearance. Below I have added an Options field, a FieldtypeFontIconPicker and a Text field to control the marker visuals via the added callback. If anyone want's to try it out, here is the link to the zip file.
    1 point
  40. Hi Guys, I think I finally solved this Or at least, I solved it for my case. The problem I had with this was that I used a form which submitted the page to a "www." variant of the page while all other standard pages where rendered without the "www.". By changing this in the config.php file I was able to keep all session variables and cookies (which previously also got dropped) $config->httpHosts = array( 'processwire.com', // our primary hostname 'www.processwire.com', // alternate hostname 'dev.processwire.com', // staging server 'localhost:8888' // MAMP local dev server ); I changed the one first to a www. variant, and the second one to a non-www. variant. in /site/config.php I hope this helps someone in the future! Bram
    1 point
  41. Background - I came across http://www.responsivebreakpoints.com/ the other day and thought it was a nice idea, but that could be done in PW using the API. In a nutshell, what it does is create an image width breakpoint at roughly every 20kb of file size between a minimum and maximum pixel size. According to this article on CSS-Tricks, "If you’re just changing resolutions, use srcset", so the markup is as suggested there. There is already the excellent Srcset Image Textformatter which works on images in RTE fields, but if you want responsive images elsewhere in your templates, you need to do the markup and decide on breakpoint sizes yourself. However, Field Templates have got you covered! Just save this as a field template file in /site/templates/fields/my_image.php as described above. <?php $maxWidth = 1000; //largest breakpoint $minWidth = 200; //smallest breakpoint $srcQuality = 40; //jpeg quality of the 'src' image $srcsetQuality = 80; //jpeg quality of the 'srcset' images $breakpointStepFileSize = 20; //i.e. 20kb $class = ""; //change this if you want to add eg "class='responsive'" $horizAspect = $value->width / $value->height; $minSizeArea = round($minWidth * ($minWidth / $horizAspect)); $maxSizeArea = round($maxWidth * ($maxWidth / $horizAspect)); $areaDiff = $maxSizeArea - $minSizeArea; $minFile = $value->width($minWidth, array('quality' => $srcsetQuality)); $maxFile = $value->width($maxWidth, array('quality' => $srcsetQuality)); $minFileSize = $minFile->filesize; $maxFileSize = $maxFile->filesize; $fileSizeDiff = $maxFileSize - $minFileSize; if($fileSizeDiff > ($breakpointStepFileSize * 1024)){ $numBreakpoints = round($fileSizeDiff / ($breakpointStepFileSize * 1024)); for($s = 1; $s < $numBreakpoints; $s++){ $breakpointStepArea = $minSizeArea + (($areaDiff / $numBreakpoints) * $s); $breakpointWidth = round(sqrt($breakpointStepArea * $horizAspect)); $breakpoints[] = $breakpointWidth; } } $src = $value->width($maxWidth, array('quality' => $srcQuality))->url; $min = "$minFile->url {$minWidth}w, "; $out = "<img src='$src' srcset='$min"; foreach($breakpoints as $breakpoint){ $bp = $value->width($breakpoint, array('quality' => $srcsetQuality))->url; $out .= "$bp {$breakpoint}w, "; } $out .= "$maxFile->url {$maxWidth}w"; $out .= "' alt='$value->description' $class>"; echo $out; Then use something like echo $page->render->my_image; in your page template and you'll get something like <img src='/site/assets/files/1/photo.1000x0.jpg' srcset='/site/assets/files/1/photo.200x0.jpg 200w, /site/assets/files/1/photo.482x0.jpg 482w, /site/assets/files/1/photo.651x0.jpg 651w, /site/assets/files/1/photo.785x0.jpg 785w, /site/assets/files/1/photo.899x0.jpg 899w, /site/assets/files/1/photo.1000x0.jpg 1000w' alt='pic' > (Bear in mind that PW has to create all these image variations on first page load, so it will take a moment.) Give it a try and see what you think!
    1 point
  42. Thanks again for the port to leaflet! I prefer OSM over google maps and have been using it for quite some time. Leaflet is very powerful and opens up many possibilities. I forked Mats' module and added support for leaflet-providers so we can choose different map tile providers (see my post here). It is still a work in progress but seems stable. Once it is ready for production I'll make a pull request. Mats, do you think we should use leaflet-providers as standard or offer the user a choice whether they want to use it or not? Next up I will add an icon field and support for Leaflet.awesome-markers.
    1 point
  43. An easy way if you wanna build a big list would be to just make a little array with all the rules and use that to filter. $excludeArray = array( "include=hidden", "parent!=2", "id!=1009", "parent!=1047", "id!=27", "id!=7", "parent!=7", "id!=1047", "id!=4945", "template!=items", "template!=antique-items", "template!=publication", "template!=publication_type", "template!=publication_section", "template!=404", "id!=2947", "path!=/processwire/" ); $exclude = implode(",",$excludeArray); $children = $page->children($exclude);
    1 point
×
×
  • Create New...