-
Posts
66 -
Joined
-
Days Won
1
Everything posted by Andi
-
Awesome module @Mike Rockett, been using this on a couple of sites last year without any hiccups. I have a case here that I'm not sure how to handle right now. Following this post Or this bit more specifically /site/templates/includes/hooks.php /** * This hook modifies the default behavior of the Page::path function (and thereby Page::url) * * The primary purpose is to redefine blog posts to be accessed at a URL off the root level * rather than under /posts/ (where they actually live). * */ wire()->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->template == 'post') { // ensure that pages with template 'post' live off the root rather than '/posts/' $event->replace = true; $event->return = "/$page->name/"; } }); I set up a hook to mask a url segment that I don't want to show up in page paths in a certain section of my site. This is all fine and dandy and working as advertised, but since the hook is living in /site/templates/ and is only affecting the front-end part of the site, the paths that show up in sitemap.xml still show the original url segment ( /posts/ in @ryan 's example) Now ideally I'd rather not mess with PW's page path behaviour in the backend, so I'm wondering if there's a way to somehow make sitemap.xml reflect the hooks from the front-end side of things without too much hacking around? Also new to hooks and trying to be careful around them ? All the best and thanks in advance!
-
[SOLVED] Find all $page->images that do NOT have the given tag(s)
Andi replied to Andi's topic in API & Templates
Dude you're fast! ? Looking great so far, nice and simple. With this in site/templates/_init.php I can do // retrieve all images that don't have mytag1 $images = $page->images_header->excludeTag('mytag1'); // retrieve all images that don't have mytag2 $images = $page->images_header->excludeTag('mytag2'); // retrieve all images that have neither mytag1 or mytag2 $images = $page->images_header->excludeTag('mytag1|mytag2'); I'll test this further and report back. Awesome stuff @Jan Romero, much appreciated!! -
Continuing my journey into PW hooks, I'm trying to find a way to retrieve all images from a page that explicitly *do not* have a certain tag (or tags) attached to them. Found this post from 2015 But I'm wondering if there's a more elegant way to go about this. Let's say I have a multi-image field called "images_header" and instead of $page->images_header->findTag('mytag'); I would like to do this: $page->images_header->excludeTag('mytag'); So I'd be able to do // find images that don't have the tag "mytag" $images = $page->images_header->excludeTag('mytag'); // check if there's any images if (count($images)>0) { // do something.. } Would this be possible by hooking into Pagefiles somehow? There's this bit in /wire/core/Pagefiles.php Line 626 that I'd basically just need to reverse (or at least in my mind ? ) public function findTag($tag) { $items = $this->makeNew(); foreach($this as $pagefile) { if($pagefile->hasTag($tag)) $items->add($pagefile); } return $items; } Any ideas on how this could be done in a graceful manner? Thanks in advance!
-
[SOLVED] Show permanent message in admin when option is selected by user
Andi replied to Andi's topic in API & Templates
Hey again, following @bernhard's suggestion of making stuff a little more readable, and after some refactoring, here's the result: In templates/admin.php // user custom theme warning in backend $this->addHookAfter('Process::execute', function($event) { // make stuff more readable $user = $this->wire('user'); // early exit if user is not logged in if(!$user->isLoggedin()) return; // array of themes that will be excluded $x = array('', 'default'); // early exit if current user theme is in excluded array if(in_array($user->custom_theme->value, $x)) return; // set up message $u = $user->name; $t = $user->custom_theme->title; // set up path for profile link $p = $this->wire('config')->urls->admin . "profile"; // send message $this->wire->warning("Frontend wird für Benutzer \"$u\" aktuell mit dem Theme \"$t\" ausgegeben. <small>Einstellung \"Frontend Theme\"im <a href=\"$p\">Benutzer-Profil</a></small>", Notice::allowMarkup); }); Also added an array of values to be excluded to make this more reusable in the future. Looking neat, working as expected. Thanks again and servus from Bavaria! -
[SOLVED] Show permanent message in admin when option is selected by user
Andi replied to Andi's topic in API & Templates
Thanks @bernhard, it really does ? I'm in my 5th or so project with PW but haven't really used hooks so far. Looks like the next best thing to a love affair ? Thank you both again for your help, greatly appreciated! -
[SOLVED] Show permanent message in admin when option is selected by user
Andi replied to Andi's topic in API & Templates
Works a treat. Thanks for explaining, that was very helpful! Here's the finished hook for future reference. In templates/admin.php // user template switch warning in backend $this->addHookAfter('Process::execute', function($event) { // only works for logged in users that have a custom frontend template enabled if ($this->wire('user')->isLoggedin() && $this->wire('user')->template_switch->value != 'default') { $u = $this->wire('user')->name; $t = $this->wire('user')->template_switch->title; $p = $this->wire('config')->urls->admin . "profile"; $this->wire->warning("Frontend der Seite wird für User $u aktuell mit dem Template \"$t\" ausgegeben. <small>Einstellung \"Frontend Template\"im <a href='$p'>Benutzer-Profil</a></small>", Notice::allowMarkup); } }); -
[SOLVED] Show permanent message in admin when option is selected by user
Andi replied to Andi's topic in API & Templates
Thanks a bunch @Jan Romero that was quick ? Very elegant and simple. And works almost perfectly, but when I set the option from "crazy" back to "default", the message pops up one more time. When I refresh the backend or navigate to a different page in admin it's gone.. Going the other way around, from "default" to "crazy", the message pops up right away. Nothing too major but I'm wondering how to work around that.. -
Getting a little deeper into the ProcessWire state-of-mind here. I seriously think I wouldn't have come back to webdev if it wasn't for this wonderful little gem of a CMS. I have an "Options" field added to all users on a site. If the user has anything other then "default" selected, I would like to show a permanent message in the admin like the one in the screenshot, only so that the user can't close it. As a friendly reminder that he changed that option from default to something crazy ? I've read up on how to send messages to users, but where would I hook into to make this show up all the time in the backend? https://processwire.com/api/ref/wire/message/ Thanks in advance!
-
@netcarver Field is showing "PLACEHOLDER" when empty, is that intentional or is there a way to configure the placeholder value? Also a default value option would be very, very neat. I'm running this on an event planner that has events almost always starting around the same time of day. Would that be hard to implement? Running version 0.2.2, field is inside a repeater in this case. Thanks a bunch!
-
Very cool module @kixe. Would it be hard to implement date formatting for custom datetime fields instead of just PW's built in "date" field? Setting up an event planner over here, where every event has a event_date field (datetime) that I'm trying to prepend to the event's url slug (or name in PW's terminology ?). If i use "event_date title" as the name format it works, if i try "event_date(Y-m-d) title" I get an error: Currently working around the issue by changing the field's output formatting directly, but I was wondering if that would be a feature that might come in handy in the future. Cheers and happy easter!
- 100 replies
-
- template
- autogenerate
-
(and 2 more)
Tagged with:
-
Hey @Mats, great module! I was playing around with pages->find today and was getting matches for pages that didn't have map markers stored to them, or at least I thought. On closer inspection in MySQL I found that there were DB rows for all pages that had the template with my map marker field, not just the ones with actual markers stored. Most of the empty records look like this data: EMPTY lat: 0.000000 lng: 0.000000 status: -1 zoom: 0 Some like data: EMPTY lat: 0.000000 lng: 0.000000 status: -100 zoom: 0 Which I'm assuming would be the ones that once had a marker which was later removed through "Clear" And some like this: data: EMPTY lat: 0.000000 lng: 0.000000 status: -100 zoom: 16 Which I guess are pages that someone just fumbled around with the zoom on in the backend ? So in order to find pages with actual map markers right now I'd need to set up my selector like template=mytemplate, map_marker.lat!=0, map_marker.lng!=0 Instead of just map_marker!="" This might also explain why the marker input field keeps popping up in page edit mode, even though I've set the visibilty to "closed when blank & open when populated". Am I missing something obvious or is this unintentional behaviour? Best regards!
-
In case anyone should need it, this still works with the latest UiKit Theme, just replace the jQuery selector with: $(document).ready(function(){ $('#pw-masthead .pw-primary-nav').append('<li><a href="https://example.com/" target="_blank">Example</a></li>'); }); Or @Jonathan Lahijani's recipe for a less quick & dirty approach: https://processwire-recipes.com/recipes/create-custom-admin-settings-page-link-in-admin-menu/
-
It seems like a long way to go, but this looks fantastic. I'll get on it asap, thanks a bunch @Robin S and @bernhard. @marcus Wondering if this might deserve a recipe, I could imagine quite a bunch of people are struggling with this issue. Thanks again, and greetings to NZ!
-
Sorry to bring up this issue once more, but I can't seem to find a proper way of implementing natural sorting for child pages in admin. I have a template for artists, and a template for paintings as child pages. The titles of paintings often contain serial numbers as in "Forest 1", "Forest 2" ... "Forest 104". So the default way of sorting paintings by title in the page tree doesn't work, as it renders as "Forest 1", "Forest 104", "Forest 2" etc. Is there a way of achieving this by hook or config option, that is paginateable and works for both front- and backend? Possibly without adding extra fields to the templates? It does seem to be fairly common use case but so far I've not managed to find a viable solution.. Also it's the first time that I didn't come across a "Oh well we do it this way in PW" within 3 minutes of research :) Any help would be greatly appreciated! Thanks in advance & good evening ya'll.
-
Ok solved, seems I ran into a issue similar to this one here All running smoothly now ?
- 41 replies
-
- photoswipe
- module
-
(and 1 more)
Tagged with:
-
Hey, first post here :) Getting a 500 Internal Server Error when installing (via URL from Github master) .. PW error log gives me a When I remove the template .module files from site/modules/MarkupPwpswpGallery the main module loads up just fine, and also renders the gallery. Have to set the template to basic though as Petersburger is the default .. Any ideas what could cause this? Great module, great CMS, great community btw :) Thanks in advance!!
- 41 replies
-
- photoswipe
- module
-
(and 1 more)
Tagged with: