Leaderboard
Popular Content
Showing content with the highest reputation on 07/28/2014 in all areas
-
I have made some nice progress: DeliveryPost done, which asks post address + email.These DeliveryModules pretty much control the whole checkout process (and also adds some admin actions). This is the part of the shop that I guess will be most often customized. It also keeps things simple, when your needs are simple. module that hooks into DeliveryPost and adds shipping options order events (or order history - what has happened and when) Oh, and the module has a name: PadLoper (named after cute turtle species) Here are few teasers:14 points
-
$page->image (assuming it has the capacity of containing multiple images) returning only first image is a problem if you're going to iterate contained images. Sure, you can make $page->image return first image of many, but then you'd need another method, something like $page->image->getArray() in order to iterate over many items. I don't think that one use case trumps another, especially since it would be a breaking change. Judging from your sample code, I'm kind of wondering if you are aware that $page->image is just a call to custom field called 'image', not something that's really built-in to the core? If that's just a proof of concept, that's cool, but in real-world use cases you can't reliably assume field 'image' to always exist Edit: forgot to mention that the ability for multi-file field to return single item has actually been added to dev branch. It's not quite what you described it (it won't work as a method) and the use case might be different from what you envisioned (though what do I know..) but you might want to check it out anyway: https://github.com/ryancramerdesign/ProcessWire/commit/83826e993ecd57af22373cc878abac8a51f11ffe. Edit 2: re-reading your post, you seem to use 'image' and 'images' somewhat interchangeably, when, in fact, there's no connection at all between these. Changing max files allowed to '1' in field 'images', like you mentioned in your post, definitely won't enable $page->image. Perhaps I'm misinterpreting this (or it's simply a typo), but if you're suggesting that $page->image should point to first item in $page->images, that's not feasible, as 'images' is also a custom field with no guarantee to be around everywhere (and any template might have dozens of other image fields too, which would then need similar logic).5 points
-
What value does $open have? I would do it like this: <?php $tenders = $pages->find("template=tender, sort=-created, tender_open=1"); echo "<h3>Tenders</h3>"; if(count($tenders) == 0) { echo '<p>There are no tenders available!</p>'; } else // Otherwise show the output { echo "Output list here"; }4 points
-
Hi jckhmmr, Any value that is posted to a page can be fetched with one of the following manners: $input->post->fieldname; $input->post['fieldname']; $input->post('fieldname'); For GET values simply change post to get $input->get->fieldname; See: https://processwire.com/api/variables/input/ Where fieldname is the name of the form input field. So when you have a form <form method="POST" action="<php echo $page->url; ?>"> <input type="text" name="firstname"> <input type="text" name="lastname"> <input type="submit" name="send" value="send"> </form> You can access those fields as follow: $input->post->firstname; $input->post->lastname; A good thing to do always with user input is to sanitize it like this: $firstname = $sanitizer->text($input->post->firstname); $lastname = $sanitizer->text($input->post->lastname); See: https://processwire.com/api/variables/sanitizer/ and welcome to ProcessWire.3 points
-
3 points
-
Hi everyone, Added some major new functionality to the edit mode today (see revised screenshot for 3. in the first post). Edit mode now includes quick addition, sorting, and deleting of pages as well as full editing via a modal popup editor, similar to the new PageTable interface, making use of MarkupAdminDataTable. If you are using this, definitely worth updating, and if you're not using it, maybe it is now worth taking a look Enable this on your home template and you have a powerful editing alternative with the added ability to automatically overwrite page names based on changed page titles, which I think is very handy during the development phase of a new site. Please let me know if you find any bugs with this new version.3 points
-
2 points
-
I updated my example so it might be more clear to you. Also for debugging you can try ... echo count($tenders); ... to show if there are any pages found.2 points
-
Sorry for the constant updates Definitely recommended to update to the latest version as it adds better handling for users without profile-edit permission. As well as the warning, it now also unchecks the force password change checkbox if the user doesn't have profile-edit permission The Set All Users role selection is now limited to only those roles with profile-edit permission Hopefully that will be all the changes for a while, unless someone has any suggestions.2 points
-
Today I've created a really simple little module that is configurable and attaches to hooks. So it has more or less everything of a real world module in it. I thought processwire beginners would be interested in reading how to create such a module so I added some comments to the source code in a way the module should explain itself... Here it is: /** * BackgroundChanger module for demonstration purposes * * Demonstrates the Module interface and how to add hooks in a more real world manner... * * ProcessWire 2.x * Copyright (C) 2014 by Domenic Helfenstein * */ class BackgroundChanger extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( /* * the __("text") methods are used for multilanguage support * see: https://processwire.com/api/multi-language-support/code-i18n/ */ 'title' => __('BackgroundChanger'), 'summary' => __('This is a simple real world module that can change the background color.'), 'version' => 105, /* * autoload must be true if the module depends on hooks * see: http://wiki.processwire.com/index.php/Module_Creation#Details_of_what_the_.22autoload.22_property_means */ 'autoload' => true, /* * it is wise to run modules in singular mode when using hooks * see: http://wiki.processwire.com/index.php/Module_Creation#Details_of_what_the_.22singular.22_property_means */ 'singular' => true, ); } public function __construct() { //set default values $this->backgroundColor = 'yellow'; /* * !!! the value in the db will be automatically injected into this var * because it is named equal to the value of $field->name in * getModuleConfigInputfields !!! */ } public function init() { // add a hook after each page is rendered and modify the output $this->addHookAfter('Page::render', $this, 'changeBackground'); } public function changeBackground($event) { $page = $event->object; //do only modify non-admin pages if($page->template == 'admin') return; $extension = <<< _OUT <style> body {background-color:{$this->backgroundColor};} </style> _OUT; $event->return = str_replace("</head>", $extension."</head>", $event->return); } public static function getModuleConfigInputfields(array $data) { //create a fieldset $inputfields = new InputfieldWrapper(); //create field for background color $field = wire('modules')->get('InputfieldText'); $field->name = 'backgroundColor'; $field->label = __("Enter the hex-code or name of the desired background color. (visit colorpicker.com)"); //if there is already a value stored, set this value to the field if(isset($data['backgroundColor'])) $field->value = $data['backgroundColor']; //add the field to the fieldset $inputfields->add($field); //return the fieldset to display return $inputfields; } } I hope this helps others creating their own modules! BackgroundChanger.module1 point
-
You can use Hanna code to replace shortcodes by html tags, or even create a formatter that turns something like (----------) in a closing and opening div. I suspect that Ryan's new Pagination Textformatter could also be a good fit for you, but I'm not sure what it does exactly yet http://modules.processwire.com/modules/textformatter-pagination/ As for me, I prefer the template way whenever I can.1 point
-
The image field is in your repeater so try this: <?php foreach($page->nuoma as $field) { echo '<div class="small-12 columns large-6 columns bobkat-nuoma">'; echo '<a class="fancybox" rel="gallery1" href="'.$field->big_img->eq($i)->url.'">'; echo '<img src="' .$field->small_img->first()->url. '" alt=""></a>'; echo '<h2>'.$field->bobkat_name .'</h2>'; echo $field->body; echo '<span>'.$field->price.'</span>'; echo '</div>'; } ?> This will show the first image of every repeater item. If you want to show every image from every repeater item you just have to add a second foreach inside the first foreach like: foreach($field->small_img as $image) {}1 point
-
Hi nfil, I'm not sure, what's the issue? Is it the image that is not working? If it is not related to mpdf, try to put your code in a "normal" Pw template under /site/templates/ and check if it works there. When everything's correct, this module should render the same output. If there are differences, that is due to limited HTML/CSS support, but the images should work. The first code example contains some errors, for example you can't write this: $count = "count()>1"; // $visavalue_b is populated now check if it is greater than 500000 if ($visavalue_b->($count)>=500000) { The second example contains no image output? Sorry I don't have time to debug, I'm away some weeks from tomorrow and I need to pack all my stuff If you have questions to general stuff Pw or PHP related, I'm sure other members can help you in this awesome forum somwhere. Cheers1 point
-
new german updates for actual PW dev 2.4.9 (28 July 2014). Zip contains only updated/added files (in comparison to the default 2.4 lang pack). updated files: wire--modules--process--processtemplate--processtemplate-module.json added files: wire--modules--inputfield--inputfieldckeditor--inputfieldckeditor-module.json pw-lang-de-dev-update.zip when PW 2.5 is ready, we have to remove TinyMCE language file from the default lang pack and offer it separately for the module.1 point
-
1 point
-
The last days I had to work a lot with PageImage. And right from the start, $page->image makes my hair weird. The stone at which I began to stumble, was the configuration part in the backend (Admin > Setup > Fields > Edit Field: images -> [Details]). Here we've to setup the maximum files allowed to 1, otherwise $page->image is not available. Is there a reason why image should not contain always the first image? I hooked into Page and made a simple method which does exactly what I've explained above: wire()->addHook('Page::image', null, 'hookPageFirstImage'); wire()->addHookProperty('Page::image', null, 'hookPageFirstImage'); function hookPageFirstImage (HookEvent $event) { $event->return = $event->object->images->eq($event->arguments[0]); }This simple hook makes it possible to do things like this (In a DIY-fashion) without repeating yourself: // Take the first image $page->image; // ...or even as a method, to take the nth image $page->image(2);Any thoughts on this?1 point
-
No problem, thanks for trying out ProcessWire - a lifesaver in itself. I almost forgot: welcome to the forums, Deyan!1 point
-
1 point
-
@everfreecreative Just a quick response to your post... Passing them in is called dependency injection (lots thrown up by google) and should make your classes more easily testable and code more reusable. It certainly can represent an "is-a" relationship but in practice I've seen it used all over the place to implement common code. This can also be done to a limited degree in PHP using interfaces and more recently through traits. Hope that helps and starts some more comprehensive answers coming.1 point
-
At first it looked like a good idea to me but I think teppo is right. How would you output all of the images if this is enabled? Normally it goes like: foreach ($page->images as $image) { // output image } But now $page->images (or $page->image) would be a string or object and not a WireArray anymore.1 point
-
Hi Yannick, I am sure others will chime in, but I don't see why this is easier than: $page->image->first(); $page->image->last(); $page->image->eq(n); Are you suggesting your approach over these options, or were you simply not aware of them? EDIT: Sorry, I see that you have been around on the forums for more than six months, so I am sure you do know about first, last, eq, and you're even using eq in your method. Sorry about that1 point
-
What about this: $np = $pages->clone($page); $np->of(false); $np->title = 'New Page'; $np->name = 'newpage'; $np->save();1 point
-
Yes. You would need to edit your post using the 'full editor'.....1 point
-
I'm getting this right now (right after updating from 2.4.3 to 2.4.5), so it's definitely an outstanding issue. Will have to dig in to see what's going on.. Edit: Just guessing, but could this be related to this commit and the part about "6) Convert Fieldtype modules to load on-demand rather than all at boot"? Looks like after the update when InputfieldCropImage runs, FieldtypeCropImage hasn't been init'd yet.. which obviously results in getThumb() not being available. Anyway, will have to debug more. Edit 2: Whether or not that was the issue, I've solved it locally by making sure that FieldtypeCropImage is loaded with InputfieldCropImage. I can't uninstall the module or try other tricks on this site, as it's already in production -- I'm assuming that Antti or Ryan will dig out the real reason (and fix) for this, but in the meantime this works for me: Index: InputfieldCropImage.module =================================================================== --- InputfieldCropImage.module (revision 7702) +++ InputfieldCropImage.module (working copy) @@ -13,7 +13,8 @@ public function init() { parent::init(); - + // make sure FieldtypeCropImage is loaded + $this->modules->get("FieldtypeCropImage"); //default settings $this->set('thumbSetting', 'thumbnail,100,100'); }1 point
-
Sounds a bit like "collection" might be a Page type field. If that's the case, try something like $page->collection->title (if it's set to contain one Page) or $page->collection->first()->title (if it's set to contain multiple Pages).1 point
-
Okay, so i figured it out, basically there was need to set the "Start" in the PageArray and that was missing in this module. I have added the following code $pages->setStart($from); right after the $pages->setLimit($size); at line # 372 in ElasticSearch.module file, and this fixed my issue.1 point
-
this topic inspired me to think about a very basic change to the existing image setup that would at least make managing images a little easier. Doesn't address the broader issues that are being talked about would at least make the existing system a little easier to use when dealing with a lot of images. main feature is it shortens the list if you have many images with fields. It will probably even let you squeeze an extra field in like "title" if you wanted it. just an idea...I really like how it works now compared to word-press or expression-engine image management.1 point
-
1 point
-
You can assign fields to templates like this: $template = $templates->get("some_template"); $template->fields->add("newfield"); $template->fields->save(); this code is taken from here http://processwire.c...bles/templates/ So, just make an array with all the templates you want the field to be on, and go for it $ts = array("home", "basic-page", "search"); foreach($ts as $t){ $template = $templates->get($t); $template->fields->add("newfield"); $template->fields->save(); } EDIT: the field will be on the last position of each template1 point
-
Hey welcome cbuck! You're not an idiot, it's ok to ask and feel dumb... You should be able to easily grab page using an instance of the category page for example.. <?php $cat = $pages->get('/blog-categories/news'); $pa = $pages->get('/blog/')->find("pagefield=$cat,template=blog-entry"); // "pagefield being your page reference field used for the categories you could also check with multiple (PageArray) categories. Same goes for sections, just combine them if you wish. You would just cycle through your categories/section and use the page object to find all blog entries with the code above. Pretty straight forward.1 point