Jump to content

artfulrobot

Members
  • Posts

    15
  • Joined

  • Last visited

Everything posted by artfulrobot

  1. The forum software is nagging me to "Help others by going to the topic and use the 'Mark as Solution’ button on the post with the best answer" but I don't see any of those buttons!
  2. Re leaking: I believe nginx uses the request url as the cache key and that only GET requests are cached (not sure about OPTIONS or HEAD). So if you have caching enabled and a logged in user, Wilma, requests /processwire/user to see their profile, the next user, logged in or not, will also see Wilma's record. Typically it's ok to disable caching for logged in users, and/or you can also disable caching on certain urls (or patterns of url) that you know to be sensitive. Don't know if this is helpful or not, but here's the sort of thing I use for Drupal. map $http_cookie $session_cookie_set { default 0; ~SESS 1; # PHP session cookie } ## Identify ajax requests so we can choose to not cache them map $uri $is_drupal_ajax_request { default 0; /system/ajax 1; } # ... then in your server block ... fastcgi_cache_bypass $session_cookie_set $arg_nocache $is_drupal_ajax_request; fastcgi_no_cache $session_cookie_set $arg_nocache $is_drupal_ajax_request; What this does is: set up a variable `$session_cookie_set` which will be 1 if there is a PHP Session cookie in the request Set up a variable `$is_drupal_ajax_request` if the path is `/system/ajax` (a special path for drupal, but you can add your own var name and url patterns in here for your own use/processwire uses). Tells nginx to bypass and not cache results if any of these, or the `nocache` URL query variable is set. I'm keen to use pw with nginx because .htaccess is ineffficient (from what I've read) and because I get on better with the reasoning of nginx's config; it seems to have fewer quirks than apache!
  3. Did this ever happen? I can't find any PageTable documentation for all my searching! It seems odd, the docs are so great, generally. (I'm specifically looking for how to create a page with several pagetable field values programmatically).
  4. Using a Page Reference field with a Text Tags input as explained in the blog post mentioned by @Robin S works. Here's the steps I had to take: Create a new Template (without template file, but might want to add one later) called tag Create a new Template (without template file) called tags. There are a few settings to note here: Family » Allowed templates for children: set to 'tag' Family » children are sorted by: Name. Create a new Page called Tags that uses the tags template and put it under Admin in the tree. Settings: Unpublished, Hidden, Locked Each tag will be a page under this. Creae a new Field using the field type Page Reference. I named mine Tags Details » Page field value type: Multiple pages Input » Input field type: Text Tags Input » Selectable pages: choose Parent: Tags (the page created above), Template: tag (the first template we created for individual tags). Input » Label field: title (default) Allow new pages to be created from this field: ✔ Add the tags field to the page template(s) you want to use it with.
  5. Thanks, will check these solutions out.
  6. Adding a files field to a template means that when I edit a page I am able to upload new files to use on that page. However, sometimes I want one file (say Annual Report) to be featured on a number of pages. Is there any way to reference a file on another page instead of uploading a 2nd copy of the file? The problem with 2 files is that they could get out of sync if they are updated, and of course, they take 2× the storage. Or is the only/correct way to do this: Create a template (do we call these page types?) "shared files" Create a shared files page: "Annual report", upload the pdf. Create a page reference field to allow users to select from shared files. The template for that page ref field follows the chain to return the file. Thanks.
  7. I added a Select Options field called tags. On the "details" settings tab I chose TextTags (Multiple sortable values) When I edit a page with this field on, and type a new tag name, e.g. 'new', it says it's going to Add new. I press <SPACE> and it renders the `new` as a tag. Then I hit Save and it compain: Removed invalid tag value: new. The UI looks like it's ok for me to add a tag, but hitting Save says otherwise. I see from the API docs: https://processwire.com/api/ref/inputfield-text-tags/ that there's an "allowUserTags" setting, but that doesn't seem to be exposed in the edit field UI? Also I observed that if I add values on for the tags field then I'm only allowed to select those, and not allowed to add new tags. Any help gratefully received.
  8. @pwired sure, here you are. site/templates/fields/sections_next.php This file is responsible for outputting rendered HTML for the field called `sections_next`. It's called with the `$value` set to the value to be rendered, which in this case is a field of type PageTableNext. <?php namespace ProcessWire; /** * @global Page $page * @global PageArray $value * @global Field $field * @global Pages $pages * @global Config $config */ ?> <div style="margin:1rem;border:solid 1px yellow; background:#ffffe0;padding: 1rem;"> This is sections_next.php <?php if(!($value instanceof PageArray)) return; foreach($value as $contentElement) echo '<div style="border:solid 1px #fc0;background:#eefff8;padding:1rem;margin:1rem;"> The following is rendered by ' . $contentElement->template->name . '<br />' . $page->renderValue($contentElement, ($field->pathToTemplates ?? '') . $contentElement->template->name) . '</div>'; ?> </div> site/templates/fields/sections/hero.php This file and the one that follow are two example possible section/paragraph/block types. For my proof of concept, I created a "hero" one and a generic "section" one. This hero one crudely renders a big background image with some big text over the top. <?php namespace ProcessWire; $image = $value->background_image; $thumb = $image->size(1920, 700); ?> <div style="background-image:url(<?php echo $thumb->url ?>); padding: 4rem;margin: 0 0 2rem 0;min-height:60vh;"> <p style="color:#fc0; font-size:3rem; font-weight:bold; text-align: center; line-height: 1.4;"> <?php print $value->title; ?> </p> </div> site/templates/fields/sections/section.php The 'section' type has a body field and a select field letting the user choose Blue/Mauve/None for the background colour. <?php namespace ProcessWire; // here, $page is the main page tht was requested; $value is the Page object being rendered, the 'section'. ?> <?php $map = ['Blue' => '#0284ea', 'Mauve' => '#f0ddff', 'None' => 'transparent']; $selected = $value->background_colour->title; $bg = $map[$selected ?? 'None']; ?> <div style="border:solid 1px #cf0;background:<?php echo $bg; ?>; padding:1rem;margin:1rem;">This is section.php, rendering <code>$value</code> <h2>title: <?php print $value->title ?></h2> <p>colour: <?php print $value->background_colour->title ?></p> body: <?php print $value->body ?> </div> Other files Now the instructions for PageTableNext (ptn) tell you to copy some other files into your templates dir, but I've not figured out why! e.g. The instructions made me copy a file from the module to site/templates/PageTableNext/ptn.php, however I put exit() at the top of that file to test whether it was ever used and I've not found it to be doing anything, so I don't understand that! Here's my demo page content: In the editor it looks like this: ➊ shows the three blocks/sections/... that I've added (with the buttons at ➌). I clicked the arrow to 'open' the third section and you can see it at ➋ rendered using just the site/templates/fields/sections/section.php file. The UI is pretty nice; you can edit each section, move them around etc. Oh, one other thing, in the main page template (e.g. basic-page.php) you need to render the field that contains all the blocks/sections/etc. like so: <?php // If using 'delayed' output: $content = $page->render->sections_next; // If using 'direct' output echo $page->render->sections_next; One interesting thing is that if you use delayed output then your site/template/{page-type-name}.php needs to populate $content (or whatever vars you use in _main.php). However, the field templates all just use echo/print because they are rendered with output buffering capture. Hope this helps! It might help me too when I come to actually make a site with PW instead of just playing!
  9. I've found a nice solution using PageTableNext. - I can define different section(block/paragraph...) types with appropriate fields, e.g. hero, text with image on right, ... I can create templates for all these. - I can add/delete/reorder/edit etc. these to a page and see previews in-editor. Thanks for the help.
  10. I have a field called 'sections', and $page->render('sections'); in basic-page. I have a templates/fields/sections.php file which is very much like your /site/templates/fields/blocks.php. It assumes templates at templates/fields/sections/{template_name}.php. I have a template called 'hero' which is set up and has content and a template file at templates/fields/sections/hero.php However, loading the page alternately gives Bad Gateway and a massive stack dump error: ( ! ) Warning: include_once(./_func.php): failed to open stream: No such file or directory in /var/www/processwire/site/templates/_init.php on line 34 I think this might be because _init is being loaded twice, once for the actual page page being loaded, and then again when called from the PageTable field template,s/fields/sections.php file which calls render() on a Page object in the loop. I found the answer in the docblock comment to the _init.php file/template: Disabling the prepend (_init) and append (main) files fixed it. So thank you, I'm getting somewhere! One thing I don't understand though is that my IDE says that the signature for Page->render() is: * @method string|mixed render($fieldName = '') Returns rendered page markup. If given a $fieldName argument, it behaves same as the renderField() method. #pw-group-output-rendering But here I'm providing a template file path?
  11. Wow, didn't expect such an awesome detailed reply, thanks! Can't wait to try it out. Re non floss docs, I may have misunderstood, but I felt like the docs for page table were not public based on things on other forum threads and also on the page that explains about the paid core 'pro' modules and how they may one day be released free but the support (which i thought might include docs) would be just for those who paid. I've probably misunderstood, so sorry if so!
  12. @kaz on my install "ProFields: Page Table" is listed in the core things I can install. I did not have to download anything extra. Perhaps you have an older version of PW? I am experimenting with that module but needing to step back to understand the rendering process; at the mo I get whole 'pages' output, with header navs etc. for each item in my Page Table field! I'm still evaluating, but I'm not sure I like/want the individual 'paragraphs' (Drupal speak) or 'blocks' (Gutenberg speak) to be separate pages with separate publication statuses, URLs etc., but I may get to something usable in the end. It's new for me to deal with the concept of non open source documentation for a (now) open source project; seems quite strange. Anyway, I'm still experimenting, I thought I should try to understand that module first before the PageTableNext one etc. Open source is a must for me, so I'm not going to evaluate Repeater Matrix.
  13. Thanks @teppo, I'll take a look at all those suggestions!
  14. I have found the 'repeater' field type which lets me repeat a set of values to a single set of fields on a page. What I'm after is something that lets me add sets of *different* fields. eg. define one thing as 'hero', which has an image and a big title. define another thing as "text with image on left" (formatted text and image fields ). define another thing as "three reasons" (a set of three text, icon, title, link fields) Now on one page I want to add: hero, text with image on left, three reasons, text with image on left. On another page I want to add: text with image on left, 3 times. Can I achieve this with processwire?
×
×
  • Create New...