-
Posts
3,058 -
Joined
-
Last visited
-
Days Won
20
Everything posted by szabesz
-
Hi PW fanatics In this post I share two of my addHookMethods for those interested. As you surely already know (if not, time to take a look at it) the Wire::addHookMethod() and the Wire::addHookProperty() API methods can be used to "breath some extra OOP" into your projects. Using addHookMethods and addHookProperty are alternatives to "Using custom page types in ProcessWire". The methods I want to share: basically the idea here is to get the URL pointing to images uploaded in the admin without writing much code in the template files. With methods like these below, it does not matter what Formatted value is set to the images, because some predefined defaults are used in all circumstances. #1 Example template file code: <?php $img_src = $latest_article->siteFeaturedImage(); ?> <img src="<?= $img_src ?>" alt="<?= $page->title ?>"> addHookMethod goes into /site/init.php <?php /* Returns URL of the original Pageimage of Article. * Image field's value can be either null (default missing image), Pageimage or Pageimages. * * @return string */ $wire->addHookMethod('Page::siteFeaturedImage', function($event) { $page = $event->object; if ($page->template != "article") { throw new WireException("Page::siteFeaturedImage() only works on 'Pages of article template', Page ID=$page is not such!"); } $article_featured = $page->getUnformatted('article_featured'); //always a Pageimages array if (count($article_featured)) { $img_url = $article_featured->first()->url; } else { $img_url = urls()->templates . "assets/img/missing-article_image.jpg"; //we show this when image is not available } $event->return = $img_url; }); ?> #2 Example template file code: <?php $img600_src = $page->siteProductImageMaxSize(600, 600, ['rotate' => 180]); ?> <img src="<?= $img600_src ?>" alt="<?= $page->title ?>"> addHookMethod goes into /site/init.php <?php /* Generates image variations for Product images. Returns URL of Pageimage. * Image field's value can be either null (default missing image), Pageimage or Pageimages. * * @param int arguments[0] Max allowed width * @param int arguments[1] Max allowed height * @param array arguments[2] See `Pageimage::size()` method for options * @return string */ $wire->addHookMethod('Page::siteProductImageMaxSize', function($event) { $page = $event->object; if ($page->template != "product") { throw new WireException("Page::siteProductImageMaxSize() only works on 'Pages of product template', Page ID=$page is not such!"); } $width = isset($event->arguments[0]) ? $event->arguments[0] : 48; //default width $height = isset($event->arguments[1]) ? $event->arguments[1] : 48; //default height $options = isset($event->arguments[2]) ? $event->arguments[2] : $options = array(); //default empty options $product_image = $page->getUnformatted('product_image'); //always a Pageimages array if (count($product_image)) { $img_url = $product_image->first()->maxSize($width, $height, $options)->url; } else { $img_url = urls()->templates . "assets/img/product-missing-image.jpg"; //we show this when image is not available } $event->return = $img_url; }); ?> BTW, you can find more examples here: How can I add a new method via a hook? Working with custom utility hooks Adding array_chunk support to WireArray addHookProperty() versus addHookMethod() Have a nice weekend!
-
Hello @madknight and welcome to the ProcessWire Forums, Have you already seen this? https://processwire.com/docs/tutorials/ especially: Installing a CSS Framework How to structure your template files also, in the newest versions of ProcessWire we have Markup Regions: https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/ and Field Rendering: https://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/ I use the above two to better structure my template files. In my setup Markup Regions is used for various page layouts where I can also dinamically add additional script and css files to a given page when needed (e.g. only the home page needs a slider JS and its CSS, etc...) I use filed rendering to render the "Main Content div" and also some fields when appropriate. I also use include when rendering fields is not possible (there are no such fields...), eg.: include __DIR__ . '/../../partials/article-lead-home.php' But there are various ways to do it. Some use templating engines for example, such us Twig, Latte, etc... You can find modules which support working with them more easily. In ProcessWire first you need to figure out your own way of setting site profiles up. It takes time, but it is worth it because you can build your "frontend theme" – which we call Site Profiles BTW – the way you want. Hope this helps. Also you can seach the forum for more ideas. Just use Google like this or similar.
-
Well, I'd better show an example, I guess. Something like this: http://www.theblog.ca/wordpress-post-notes On the WP dashboard there is a "collaboration notes made by others" and underneath there is an AXAJ form to add more notes. It is like a simple message board when used with this simple setup. This WP plugin has more to it than a "global" message board, but I've never tried those features. Most of the time a simple FB like flow of conversation is enough when only a few editors are using a site. Maybe your module is not about such a feature?
- 19 replies
-
- 1
-
-
- conversation
- messaging
-
(and 1 more)
Tagged with:
-
I am wild guessing here but do you have "Check for upgrades on superuser login?" turned on? The Upgrades module utilizes loginHook and maybe your other 3rd party module too and there might be some conflict there.
-
back to the roots: problems with simple hooks :(
szabesz replied to bernhard's topic in API & Templates
Maybe related: https://github.com/processwire/processwire-issues/issues/319 There seems to be some mayor issue with setAndSave(). -
get data of pages with checked and unchecked property
szabesz replied to fabjeck's topic in General Support
Thanks, I fixed it above. -
Hi Csaba and welcome to ProcessWire, Can you please provide more info about the issue you are having trouble with? We need to see your actual code you are trying to use to display those links/pages so that we can help you out. Also, maybe you are modifying some existing site profile? If so, which one?
-
Hi @benbyf What is "Memebers"? Jokes aside, I would love to see "shared message boards", seen by defined group members (roles), so that site editors/administrators can send/discuss important messages in order to better collaborate, say on a dashboard which loads first when logging into admin. Does your module support something like that? I cannot seem to decipher this from your description above. Thanks in advance, BTW, sounds like a nice module anyway.
- 19 replies
-
- 1
-
-
- conversation
- messaging
-
(and 1 more)
Tagged with:
-
One might also find it helpful for batch changing pages and more. @adrian's great helper tool, the Admin Actions module:
-
Currently I have no issues with Upgrades module connecting to GitHub either. In the past once I had issues with it too, but at that time GitHub was brought down by DoS attack or something like that.
-
So you either have to downgrade to PHP 7.0.x or wait for @justb3a to update the module. You can "hack it" too, either by actually changing the module's code or you can try the "multiple copies of the same module" technique: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/ I never did the latter, BTW.
-
get data of pages with checked and unchecked property
szabesz replied to fabjeck's topic in General Support
Hi, Written in the browser – so please excuse my possible mistakes – but one possible solution is not to include the 'limit=$limit' part when you do not need it. Something like this function findArticles($limit, $force) { $force_str = $force === "" ? "" : "force=$force, "; //inject nothing into the selector string if force is empty $selector = "template=article, sort=-published, limit=$limit, $force_str" . trim($selector, ", "); $articles = pages($selector); return $articles; } May the force be with you, BTW -
PHP version? 7.1? Or something way older? https://www.google.hu/search?q="[]+operator+not+supported"+php&oq="[]+operator+not+supported"+php
-
+1 tip then: https://www.lynda.com/learning-paths/Web/become-a-full-stack-web-developer I find that Lynda's video tutorials are among the best ones and with a subscription you can watch them "all". Those that are linked on the page above are good ones to begin with but after watching/doing "Programming Foundations: Web Security" you might want to jump right into ProcessWire because by that time you will have learned enough. These tutorials do not seem long, however, if you don't just watch them but copy what they do (which is recommended) then it can take weeks to do them all. ProcessWire is the best CMS for complete beginners, you've come to the right place, BTW Good luck!
-
is it possible to link directly to the content or delete tab?
szabesz replied to bernhard's topic in General Support
hi @bernhard Can't you just use the complete URL instead? -
Oh, yeah, thanks! Then its even simpler to fix: echo ukAlert("Found {$matches->getTotal()} page(s)", "default", "search");
-
@ryan Currently we count the numper of pages listed on a paginated page (50 or less) and not the actual number of pages found. A possible fix for this in search.php: $selector = "title|body~=$q, has_parent!=2"; // Find pages that match the selector $matches = pages()->find($selector . ", limit=50"); $matches_many = pages()->findMany($selector); ... echo ukAlert("Found $matches_many->count page(s)", "default", "search");
-
@ryan one more thing I found: $input->whitelist('q', $q); is missing from search.php
-
Welcom @AlyxGD! I recommend starting with these, in this order: https://processwire.com/docs/tutorials/but-what-if-i-dont-know-how-to-code/ http://www.how-to-build-websites.com/ https://processwire.com/docs/tutorials/hello-worlds/ https://www.youtube.com/watch?v=-3Fwyd5Okrg&list=PLXlVJXqzkgyqQJyxkb4hai3WgoPoD8osO&index=1 https://processwire.com/docs/tutorials/installation-moving-and-troubleshooting/ If after checking these above you still feel like diving into web development, I recommend installing ProcessWire on your own machine to play with it a little bit to get the hang of it. If you don't feel like dealing with all you've seen above, I recommend looking for a ProcessWire web developer: https://processwire.com/talk/forum/22-jobs/
-
This is because as the inventor says: "ProcessWire IS a native category system, whether by structure or relation. I think the distinction is that we don't call them "categories" or "tags". But "does not have" makes it sound like they aren't part of the plan. When in fact, it's one of the underlying purposes of the system." to read more:
-
[solved] why is $li.trigger('opened'); fired twice in the pw admin?
szabesz replied to bernhard's topic in General Support
+1 and it also flashes a few times instead of closing it. -
Loosing session in certain network environments
szabesz replied to gebeer's topic in General Support
Reminds me of this one: Is it a similar or same issue? I'm not quite sure, that's why I'm asking. "They have two VDSL lines into the building that feed their router through a load balancer. It seems that their setup meant that responses to outbound traffic did not necessarily come back in via the same line." -
I woke up this morning and this was the very first forum topic I had read. I was really happy to start the day with a ProcessWire success story, it made my day. Thank you for sharing it with us and keep up the good work! Cheers from the other side of the Globe
-
In addition to all the above. @Sipho If you want to make sure hidden pages never show up accidentally (say they have a template, guest access, and someone happens to know/figure out its URL) then you can turn hidden into password protected with @adrian's great PageProtector module easily: Another tip when dealing with related data: you might want to take a look at @Robin S's cool module: Hope this helps too.
-
Oh I see, banging on open doors again Thanks for the info!