Jump to content

LMD

Members
  • Posts

    86
  • Joined

Profile Information

  • Gender
    Not Telling
  • Location
    Europe

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

LMD's Achievements

Full Member

Full Member (4/6)

95

Reputation

  1. I can't test this right now, but it might be simpler to put your functions in a separate file (e.g '_funcs.php') and then in '_init.php' use: // in _init.php require_once '_funcs.php'; By using 'require_once', it shouldn't matter how many times '_init.php' gets called, the '_funcs.php' file will only be included once.
  2. You can configure VS Code to understand "*.module" files as PHP. Go to "Settings" and then "Text Editor > Files". Under "Associations" press "Add" button and add "*.module" (without the quotes) under Item/key and "php" under Value. Hit "Ok". Might need to restart VS Code for it to take effect. Also, you need a double-asterisk at the front of the comment to get the code hints (and also make sure the variable name is correct/matches!): /** @var TextformatterMarkdownExtra $md_formatter */ $md_formatter = $modules->get("TextformatterMarkdownExtra");
  3. You forgot to call the fieldname 'button' - you are echoing the repeater items (which uses the ID as toString output). Try this: <div class="caption-cta-wrapper uk-margin-medium-top"> <?php // 'buttons' is a repeater field, so '$btn' is a repeater item foreach($page->hero->buttons as $btn) { echo $btn->button; // <-- fieldname! } ?> </div>
  4. Hi @fruid At the moment it looks like you are grabbing all pages (with parent id = 1) and iterating through them individually to find the ones matching the required menu. With a small number of pages this may well be perfectly fine, but if there are hundreds/thousands of pages it's not very efficient. It would be better to just grab only the pages in the required menu - unfortunately you can't (currently?) do that with a PW selector, but you can use a MySQL query directly combined with a PW find selector -- check out the following thread:
  5. In this case, you really need to ensure the user has the correct country code, otherwise there is a scenario where they could login to somebody else's account by accident! How about pre-filling the field, but not making it invisible, so the user can see and check it is correct? Maybe with a little country flag icon?
  6. I'm on a mobile, so can't test this but you could try the following... Create a dummy SVG file with a placeholder icon and module name all aligned and styled properly. Give the placeholder icon and text span containing the changable module name unique IDs. I assume the real icons are also SVG (e.g. FontAwesome) and not an image? On page save (with PHP, I assume), open the dummy SVG and regex search-replace the icon (open the icon code too if necessary) and module name. Save new code as a new SVG file. That would be my stating point.
  7. Is the number part of the username unique to each user? If so, why complicate things with the region part at all? Especially if you only want the user to enter the number. I fear that by asking too much of the user (making sure their region matches), it will just lead to more tech support enquiries.
  8. This page in the docs helps, but basically inside a module you can use: $this->page; $this->wire('page'); // preferred in Wire-derived classes (i.e. modules) However, for the example you gave above (renderPageTitle()), it might be easier to create a new method for the $page class with a hook. For example: /** * NOTE: the module will need to be set to be 'autoload' => true in the Module Info */ class MyModule extends WireData implements Module, ConfigurableModule { /** * Run when PW is "ready" (like ready.php file) - so it's where you place you ready hooks. */ public function ready() { // Add a hook to define the "renderPageTitle" for the $page class. // Called in your templates with with $page->renderPageTitle() $this->addHook('Page::renderPageTitle', $this, 'renderPageTitleHook'); } /** * The hook code itself (could have been an enclosure on the hook if simple enough) */ public function renderPageTitleHook(HookEvent $event) { $page = $event->object; // the $page class *instance* calling the method $event->return = $page->title; } } Alternatively, this is a good case for using Custom Page Classes (look at the most recent 'site-blank' profile for an example).
  9. In the regular site profile you can find the function that controls this output in the file called '_uikit.php' in the templates folder. Find the function 'ukBlogPost()' and go to the line defining the variable '$date' (see here on Github) to change it. Currently it is looking for the date (modified) and falling back to the created date string 'date|createdStr' -- just remove the 'date|' bit and leave 'createdStr'. Be sure to check the other functions in that file for other places the date may be displayed.
  10. Ahh, yes, I was not taking into account 'Pages' vs 'Page' objects. Which is silly of me, because the clue is right there in the "$page = $event->arguments(0)" bit of the hook method! Thank you!
  11. I'm trying to use a conditional "saveReady" hook for repeater items inside a module, but for some reason it isn't firing (and yes, I am making sure to make changes to the repeater when testing!). It works when NOT using a conditional hook (and checking for the template inside the hook function itself), so it's not an issue with anything except the conditional part of the hook. // THIS WORKS public function ready() { $this->addHookAfter('Pages::saveReady', $this, 'myHook'); } public function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name === 'repeater_gallery') { bd($page); // Tracy dump } } // THIS DOES NOT WORK! public function ready() { $this->addHookAfter('Pages(template=repeater_gallery)::saveReady', $this, 'myHook'); } public function myHook(HookEvent $event) { $page = $event->arguments(0); bd($page); // Tracy dump -- does not get dumped. Is the hook not fired? } I'm using the latest DEV version of ProcessWire (v3.0.222). Is this a bug, or is it me?
  12. Ahh, yes.... I've only been putting it on the local parent element where required, because the <body> is controlled by a different template. But if your entire site is HTMX powered that is absolutely the way to go.
  13. I'm developing a site using HTMX to swap images in a gallery (it uses 'picture' element and 'srcset' so I didn't want to load all the markup at once) alongside PW regions and it works great. I haven't really encountered any problems or gymnastics -- but maybe my use-case is simple enough? <?php namespace ProcessWire; $imgMarkup = ''; $thumbMarkup = ''; $imgNum = 0; /** Build the gallery fragment (the bit that changes via HTMX) before output */ if ($page->gallery && $page->gallery->count() > 0) { $imgNum = $input->get('img', 'int', 0); // get image index number from GET var (AJAX and no-JS) $galleryImg = $page->gallery->eq($imgNum); // get the image from index // The image markup (actually rendered from a custom page class) $imgMarkup = '<picture> <source type="image/webp" srcset="..."> <img src="..." width=".." height="..." alt="..." srcset="..." sizes="..."> </picture>'; // If it is a ajax (HTMX) request, just echo the image markup and stop PW processing tyhe rest of the template. if ($config->ajax) { echo $imgMarkup; return $this->halt(); } /* When doing HTMX ajax swap, the rest of this template won't be rendered */ // Build the clickable thumbnails that do the swapping (simplified) foreach ($page->gallery as $item) { $thumbMarkup .= '<li><a href="..." hx-get="..."><img src="..." width="..." height="..." alt="..."></a></li>'; } } ?> <!-- The markup regions --> <pw-region pw-id="imageViewer"> <div class="image-wrapper"> <figure class="image-main-wrapper" id="mainImg"> <?=$imgMarkup?> </figure> <div class="image-thumbs-wrapper"> <!-- where the HTMX magic happens -- note the additional hx-headers, which allows PW's $config->ajax to work --> <ul class="image-thumbs" hx-trigger="click" hx-target="#mainImg" hx-swap="innerHTML" hx-headers='{"X-Requested-With": "XMLHttpRequest"}' > <?=$thumbMarkup?> </ul> </div> </div> </pw-region> <pw-region pw-id="pageContent" class="content-left">....</pw-region> <pw-region id="sidebarContent">...</pw-region> It just works... no need to faff with cancelling prepend/append templates etc, just rember to add the extra hx-header (also, you can do it once on a parent element), you don't need to add it to every call. I haven't ever tried, so I'm not 100%, but there might be a way to automatically add the header to every HTMX call with a bit of javascript in the header/footer. I feel all the tools are probably already there, but if there is an even easier way, though, that would be great.
  14. Not a problem, this time, but an FYI and a solution in case anybody needs it. When using a Dynamic Options field as an images/files custom field, the 'page' value of 'arguments(0)' is not the page being edited, but instead it's a dummy page used for the 'field-fieldname' template. If the actual page is required for some logic (a need I had), then this poses an issue... but there is a solution! In your 'getSelectableOptions' hook, do the following: $wire->addHookAfter('FieldtypeDynamicOptions::getSelectableOptions', function(HookEvent $event) { $page = $event->arguments(0); // Page data (which will be wrong for our specific use case) $field = $event->arguments(1); // Field data // 'foo' is an images custom field if ($field->name === 'foo') { /* Get the page -- where we get page from will be different in the admin (edit) and frontend.*/ $page = $this->page; // the current page route (sufficient for the frontend) /* However, in the admin edit page (check the process) */ if ($page->process === 'ProcessPageEdit') { // Get the id of page being edited from $input and then use that to fetch the page $page = $this->pages->get($this->input->get('id', 'int')); } $options = []; // empty array to return if no valid page is found // If it is a valid id... continue as usual, using the $page var if ($page->id) { if ($page->template->name === 'gallery') { $options = ['foo' => "Foo", 'bar' => "Bar"]; } else { $options = ['lorem' => "Lorem", 'ipsum' => "Ipsum"]; } } $event->return = $options; } // ... other fields as required can use the $page from args }); No idea if there is a different way, but this method is fairly simple, besides, it's not going to be a common issue. Hope this helps somebody. Here's the Tracy dump of the custom field "page" for the curious: ProcessWire\DefaultPage id: 0 name: '' parent: '' status: 'corrupted' template: 'field-images' caption: '' foo: => '' data: array 'caption' => '' 'foo' => ''
  15. When generating a WebP image from the originally uploaded file (not as a result of using the 'size()' method), I see the following file error in the logs: unlink: Given filename is not a file or link: /site/assets/cache/WireTempDir/.PFM0.24368300T1680350648RozEvGgLCG8JdZGUwLM/0/cookies.960x0.png-tmp.png Note that the actual original filename is 'cookies.png' -- but the error message appears to show PW has attempted to use a (non-existant) variation. The simplified code I'm using in the template (it will eventually be a srcset, hence the small 'width' to large file): // Cut code fetching the $img itself echo '<img src="' . $img->webp->url . ' " width="300">'; The strange this is, that the correct WebP image *is* generated and subsequently served ('cookies.webp'), it just throws a hissy fit while doing it (once generated no error is shown). This error does not occur when generating WebP images from variations. Is this a known issue, should I submit an issue on Github?
×
×
  • Create New...