-
Posts
90 -
Joined
Everything posted by LMD
-
I have a strange problem and I don't know if it's bug or I'm just not quite understanding something right. I'm using ProcessWire 3.0.34. I have a search box fragment (the HTML) in a separate template which I 'include' via wireRenderFile() because I'm using the delayed output method for my templates. It works perfectly well, and shows the form. However, on the search results page, I also want to show the keywords that were entered in the search text input. This should be easy, my search function sanitises the user input (the search form uses GET) as a selectorValue and saves it to the $input->whitelist. This is where it gets weird. On the search results page itself I can spit out the whitelisted variable ok for the "you searched for 'blah'" text, but it doesn't get passed to the file included by wireRenderFile to show in the search form text input. I thought all PW API variables (in this case $input) were available to included files and that only custom variables had to be passed as an array? My first thought was that there is a context issue, so I tried wire('input') instead, but that didn't work either (and it didn't show an error), so my second thought was that maybe $input is not passed automatically and only the $page object is ($page->whatever does work), so I tried to pass the value I wanted as a custom variable: $page_body .= wireRenderFile("includes/comic-search-form", array( 'search_keywords' => $input->whitelist->search_keywords )); // Note the variable works perfectly elsewhere on the template calling wireRenderFile: $page_body .= "You searched for: {$input->whitelist->search_keywords}"; // WORKS! In the included file, I then used: <input type="search" name="search_keywords" id="search_keywords" size="30" placeholder="Enter keywords" value="<?php echo $search_keywords; ?>"> <!-- note, when working, the code will check the $search_keywords actually has content before echoing --> However, it still came out blank! So I did some more tests passing other variables and also used Tracy Debugger to var dump: bd($input->whitelist->search_keywords, 'Before'); $page_body .= wireRenderFile("includes/comic-search-form", array( 'test_a' => $page_summary, // another custom variable from the template 'test_b' => 'This is a test', // a direct string 'search_keywords' => $input->whitelist->search_keywords )); // On the incude file itself, I did the following bd(array($test_a, $test_b, $search_keywords), 'Inside wireRenderFile()'); echo "<pre> Test A (variable): $test_a Test B (string): $test_b Search Keywords: $search_keywords </pre>"; In the Tracy output and the directly printed output the $test_a and $test_b variables worked perfectly as expected, but the $search_keywords was always blank (null)! Weirdly, in the output on the template calling the wireRenderFile ("Before"), the Tracy output for $input->whitelist->search_keywords was also blank!? If I can echo out the $input->whitelist->search_keywords value on the template it is called on, why can I not then save it as a variable to be passed to wireRenderFile ? Is there something I am overlooking or not understanding?
-
I'm not sure automatically clearing when a template file is changed is worth the overhead (unless PW already does the steps necessary to achieve it). The system would have to check the modified time of every template file to decide if it is newer than the cached version _every time_ a page is loaded/rendered. Yet template updates shouldn't be that frequent once a site is up and running (so it would mostly be a wasted overhead), and when they do happen it would still be easier on the system to just disable the cache completely while those updates are being made. And what about changes to files that are included into a template, which the PW system won't necessarily 'know' about in order to compare modified dates?
-
@Robin S It has nothing to do with the default behaviour of the template cache -- it is clearing the cache when it should do. At least I've not noticed any issues when logged-in, saving pages or using GET/POST whitelist. Adding/removing/changing fields - I don't know, but adding fields is at least usually accompanied by modifying pages (to add the new data), which would clear the cache. However, making changes to the template files does not clear the cache. Which is one of my issues. My other issue is laziness If I'm logged-in (which would prevent caching), I'm not getting the normal visitor ('guest') experience/view. I just wanted one simple place to disable the cache temporarly for multiple templates, without having to log-in, add a no-cache GET variable (and then have to add it to every URL in dev) or disable it on every template that uses it. it would also be useful on staging sites, where you may enable caching to show clients how fast it can be (and for testing), but might want to disable it when making changes. Or even on the live site itself -- globally disable the cache (and then dump it via the module's settings page), make the updates/upgrades while the cache is disabled (preventing visitors from triggering caching), then once the updates are made/tested, enable the cache again. This is where Soma's solution works a charm - it creates that simple/quick config setting and and only involves a few lines of code in the ready.php file.
-
Thank you Soma. Yeah, I know about being logged-in and GET/POST vars, but that wouldn't apply here (need to view the site when logged out too). However the code you suggested is perfect and does the job. I modified it slightly so it will work in the ready.php context: // Code for ready.php context instead of module context $this->addHookBefore('Page::render', null, 'doNotCache'); function doNotCache($event) { if(wire('config')->disableTemplateCache) { $args = $event->arguments(1); $args['allowCache'] = false; $event->setArgument(1, $args); } } This could easily be expanded to look for sessions/cookies too that aren't related to being logged-in but might necessitate disabling the cache while they are present (either globally or on particular templates/pages).
-
Is is possible to temporaily disable template caching on all templates without having to go through each template and manual disable it in admin? I'd like to keep my development site and live site settings the same (it makes migrations easier), including the template cache settings, but want to disable the _actual_ caching (except for testing) on my dev site. Is there a config or other setting I can use in just one location (preferably in config-dev.php) that will achieve this? Also, this is more iof a secondary/wish-list issue, but it would be nice if the cache could be disabled for specific SESSION vars (when not logged-in) as well as GET/POST vars.
-
I'm experiencing an issue with the page reference field-type (FieldtypePage) when I set the "page-edit-created" permission for a custom role on the template of the pages being referenced. I'm using ProcessWire 3.0.28 devns with the default admin theme (on my local XAMPP set-up). This is what's happening: I have a list of comics and genres ("categories") which reside in the page tree under the home page: Home Comics [parent: comics_archives] Comic #1 [child: comics_single] Comic #2 Etc... Genres [parent: comics_genres] Genre Title #1 [child: comics_genre_single] Genre Title #2 Etc... On the comics template (comics_single) there is a page reference field to select genres. The page reference field has the following settings: Details Tab Multiple Pages: PageArray Input Tab Selectable Pages: Parent: Genres Template: comics_genre_single Label: Title (default) Input Type: AsmSelect Link selected pages to page editor: No. Allow new pages to be created from field: Yes (checked) I do not have any special "Access" permissions assigned to the field itself. I have a custom role ("bcn-author" -- * see end of post for permission settings for role) that is allowed to View/Edit/Create new genres. The templates have the following "Access" settings: comics_genres: View Pages / Add Children (no need to Edit this page) comics_genre_single: View Pages / Edit Pages / Create Pages When using the page field while logged-in as a user with the custom-role assigned, it works as it should. There is a "Create New" link on the page field in the comics template and the user can add new genres (it also works as expected in the page tree view). However, my problem arises when I assign the "page-edit-created" permission for the custom role under "Additional edit permissions and overrides" on the "comics_genre_single" template. Then, the "Create New" link disappears on the page reference field on the comics template (they can still add existing genres). Although it is still possible to add new genre pages from the page tree; so it seems to be just related to the page reference field (FieldtypePage). I'm trying to set this permission because I do not want users to be able to edit genres once they have been created -- I can not find this as an option though (you can not check "Create Pages" without "Edit Pages" also being checked on the "Access" tab), so I thought limiting user's ability to edit to just their own genres pages would be a compromise. Also, I'm successfully using the "page-edit-created" permission on the comics templates, so it doesn't seem to be related to the permission by itself. It's puzzling me -- have I overlooked something obvious, or is this actually correct behaviour and I've misunderstood something? ~ LMD * Permissions settings for "bcn-author" custom role (note: screenshot was taken after I had _removed_ the "page-edit-created" permission from "comics_genre_single" template, so it does not show here).
-
Oh! You are quite right. Thank you. I got completely stuck into a single way of thinking (that siblings would result in a less exhaustive search) and totally blanked there. I forgot that I could use 'parent=$page->parent', even though I've used that formulation elsewhere for other things -- you know what happens when it's just you, four walls, a computer and nobody to bounce ideas off. Although, I'm not actually calculating the episode numbers for any purpose other than the navigation so using the new next/prev would make for less code there, but on the hand it might still be more efficient to stick with the findOne method.
-
Hi, my first post here on this forum -- I've been experimenting with PW for about a month now and just launched my first (personal) site using the system. Because it's a site for myself, I've been using the 3.x version of PW for the 'bleeding edge' stuff and this new update is in fact very relevant right now. The site is a webcomic, which has 466 pages/episodes in sequence (a number that could potentially grow to the thousands), each of which have a "first/previous/next/last" navigation bar. Currently, because of the warnings on methods like next() becoming slow with many pages, I fetch the pages for those navigation links using the following code: // Note: 'comic_epnum' = field containing the episode number (the most reliable field for sequencing) // Previous episode $nav_prev = $page->siblings->findOne("comic_epnum=" . ($page->comic_epnum - 1) . ", sort=comic_epnum"); // Next episode $nav_next = $page->siblings->findOne("comic_epnum=" . ($page->comic_epnum + 1) . ", sort=comic_epnum"); As you can see, to remove the need to load all pages into memory, the 'previous' and 'next' are obtained with the findOne() method on siblings() by calculating which episode number to fetch. Am I right in thinking that I could now safely replace that code with the following without any potential performance hit? $page->prev('sort=comic_epnum'); // Previous episode $page->next('sort=comic_epnum'); // Next episode We can not use findOne() to obtain the 'first' and 'last' episodes because we do not know what episode numbers they will be (well, the first will most likely be #1, but maybe you want to start on a different number). Therefore, results are obtained from siblings() with first()/last(), however these could also suffer from inefficiency (according to footnote on this page of the docs: https://processwire.com/api/variables/page/ ), so I got around that by using a selector to limit the number of returned pages to one (1) and just reversing the sort to get the last episode. // First episode (most like #1) - could use $pages->findOne('comic_epnum=1') $nav_first = $page->siblings("sort=comic_epnum, limit=1")->first(); // Last (most recently published) episode $nav_last = $page->siblings("sort=-comic_epnum, limit=1")->last(); The update doesn't actually say anything about first() and last(), so I am assuming they haven't been modified. But, I wonder if that could be something to look at in the future, so that the following could be super efficient too? $page->siblings('sort=comic_epnum')->first(); // First episode $page->siblings('sort=comic_epnum')->last(); // Last episode // Or even... $page->first('sort=comic_epnum'); // First episode $page->last('sort=comic_epnum'); // Last episode In fact, I don't understand why first and last are an issue with many pages, because they do not need to know the current pages position relative to its siblings. Anyway, sorry for my long-winded intro to this forum. In the short while I have been using ProcessWire, I have been very impressed. I'm coming from a background of WordPress wrangling, where the first thing I had to do on any project was remove everything I didn't want (that could be removed). [Edit: oops, and the website is: http://www.tranquilitybasecomic.co.uk ]