Jump to content

Robin S

Members
  • Posts

    5,039
  • Joined

  • Days Won

    340

Everything posted by Robin S

  1. Just wanted to add that you can override an automatically prepended/appended file for a template on the Files tab of Edit Template. If you know you never want those automatically prepended/appended files for the template then this is the way to go. The $use_main approach is more suitable when some of the time you want the appended file and some of the time you don't (for an AJAX-loaded page, for instance).
  2. There's no absolutely right or wrong way - if you asked 10 people you'd probably get 10 different answers. It comes down to what you find most comfortable to read, write and maintain. Personally I like a single auto-appended main.php containing the HTML head, body and any "framework" markup that will appear on all pages. For blocks of content I use variables defined in an auto-prepended init.php and overwritten in template files where needed. I like to use output buffering when populating my "block" variables: <?php ob_start(); // $side_col ?> <div class="side-col"> <p>Something else here.</p> <?php // some PHP here ?> </div> <?php $side_col = ob_get_clean(); ?> Generally my approach would be to use main.php for all templates including the home template - anything unique to the home template would be inside the main "block" variables. But here's another way: I have a $use_main variable defined as true in init.php, and at the top of main.php I have if(!$use_main) return; So if I don't want the contents of main.php appended I can set $use_main to false in a template and then use alternative markup. You could do this in your home template. I think in this case I would create a different template for this ("article_categories"), but it would "extend" the parent articles category so I'm only changing the parts that need to be different. I do this by including the template to be extended at the start of the template file. // template extends... include './articles.php'; Then in article_categories I overwrite the variables I want to change from what is defined in the articles template. Alternatively you could use a single template for both articles and article_categories and use some logic inside it to change the output. if($page->parent->name === 'articles') { // then this is one of the article category pages } This is probably the result of template "Family" settings.
  3. You're absolutely right that neither would work with $pages->find() - I didn't think that through. But I think it should be possible to use the property in an in-memory selector, like: $results = $some_pagearray->find("lastModifiedStr=10 days ago"); Trouble is I can't test this as I can't get the code example in the API reference for addHookProperty() to work. Does it work for you? For me the hook never fires and I just get NULL for $page->lastModifiedStr. The same hook code works fine when in addHook() or addHookMethod() and called with $page->lastModifiedStr().
  4. One difference that just occurred to me is that the property may used in a selector but the method may not. So in the examples from my last post I could do... $results = $pages->find("lastModifiedStr=10 days ago"); ...but not... $results = $pages->find("lastModified=10 minutes ago"); Is that right?
  5. Thanks. I'm sure I'm missing something here, but it seems like addHookMethod() can do everything that addHookProperty() can plus it can optionally take arguments. In the Hooks docs there is this example for addHook(), aka addHookMethod(): public function init() { $this->addHook('Page::lastModified', $this, 'lastModified'); } public function lastModified($event) { $page = $event->object; $event->return = wireRelativeTimeStr($page->modified); } echo $page->lastModified(); // outputs "10 minutes ago" And then in the addHookProperty() API reference there is virtually the same example: // Adding a hook property $wire->addHookProperty('Page::lastModifiedStr', function($event) { $page = $event->object; $event->return = wireDate('relative', $page->modified); }); // Accessing the property (from any instance) echo $page->lastModifiedStr; // outputs: "10 days ago" So the addHook() example could alternatively be added with addHookProperty(). But if addHook()/addHookMethod() can "do more" than addHookProperty() thanks to the ability to pass in arguments, in what circumstances would you want to use addHookProperty()?
  6. I'm hoping someone might explain the difference between addHookProperty() and addHookMethod() and when you would use one over the other. One of the things I find confusing is that the docs for addHookMethod() say that it is an alias for addHook(), yet the example given for addHook() in the Hooks documentation is the same is the example given for addHookProperty() in the new API reference.
  7. v0.0.2 released - a complete overhaul of the module. Custom Inputfield Dependencies now does the same thing but in a completely different way (thanks to a great idea from @adrian) The module no longer requires Hanna Code and inputfield dependencies are now set on the "Input" tab of "Edit Field". See the first post for all the details. If you are using v0.0.1 of the module then this is a breaking change and you will need to redefine your dependencies (sorry ). But the new approach taken in v0.0.2 is so much better that hopefully you'll find the change worthwhile.
  8. I tested this and can confirm the issue - I believe it's a bug and created a GitHub issue for it: https://github.com/processwire/processwire-issues/issues/152 The issue only occurs when both Page fields are 'single' fields.
  9. You could FTP your files to an "uploads" directory and them import them to a field on a page using the API. For example, to add PDF files in /uploads/ to a field named "files" on the Home page... // function for adding files function addFiles($file_extension, $page_id, $files_field_name) { $files = glob( wire('config')->paths->root . "uploads/*.$file_extension" ); $p = wire('pages')->get($page_id); $p->of(false); foreach($files as $file) { $p->$files_field_name->add($file); } $p->save(); } // call the function with arguments to suit addFiles('pdf', 1, 'files'); Remember to delete the files from the uploads directory after each successful import.
  10. You can also find the admin page name (and thereby the URL) by viewing the "pages" table in phpMyAdmin or similar. Look for the row with the id of 2.
  11. I misread your post and thought you meant Select Multiple rather than Page List Select Multiple - the latter is fine for thousands of pages as it is ajax-paginated.
  12. Not very well - that's when you would want to use an inputfield that loads options on demand with AJAX. I think Autocomplete is the only core inputfield that does this. Misread your post and thought you meant Select Multiple. Page List Select Multiple uses the standard ajax-paginated page tree so that is fine for thousands of pages, although slower to use than Autocomplete. Inputfield Selectize is based on selectize.js which does have an AJAX load feature but I'm not sure this is available for pages in the PW module.
  13. Maybe I'm misunderstanding something, but a Page field seems ideal for what you want to do. You leave the Song pages where they are (under Songs in the tree) and then select them in a "Songs" field in your "Playlist" template. Several of the available inputfields for a Page field allow you to sort pages in the field - Autocomplete is a good option for selecting from a large number of pages but you could use AsmSelect or some other inputfield if you prefer. In the screenshot below, imagine these "vegetable" pages are instead songs. This way you don't need any child pages under your Playlist pages. P.S. I think you forgot to add your screenshots.
  14. Rather than making duplicate Song pages as children under the playlist, could your Playlist template have an Autocomplete Page field "Songs" where you select Song pages?
  15. Media Manager might be the slickest option for this. Not 100% sure but I think it allows you to upload new media directly from a page being edited. If you want a no-cost solution you could look at adapting this module from @mr-fan, which is based on code by @adrian https://github.com/mr-fan/AutoImagePages But it doesn't allow for the uploading of new files directly from a page being edited - you must upload from the parent page of the files/images branch.
  16. There are a couple of solutions linked to in this topic in the FB VIP forum.
  17. HTML renders fine for CKEditor fields. For text or textarea fields there are two possibilities: Strip the tags... $this->addHookBefore('Fieldtype::markupValue', function($event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $value = $event->arguments('value'); if($field->name == 'my_field' && $page->template->name == 'my_pagetable_template') { $event->arguments('value', $this->sanitizer->textarea($value)); } }); ..or decode entities (being mindful of potential security risks that this opens up)... $this->addHookAfter('Fieldtype::markupValue', function($event) { $field = $event->arguments('field'); $page = $event->arguments('page'); if($field->name == 'my_field' && $page->template->name == 'my_pagetable_template') { $event->return = html_entity_decode($event->return); } });
  18. @Ivan Gretsky, did kongondo's reply solve your issue? If you mean the additional template restrictions added by TemplatesChildPages, I didn't include a method for returning the allowed templates as the module is only intended as an admin helper (and it only autoloads on admin pages). If you still have a need to get the module's template restrictions for a given parent via the API let me know and I'll look at adding a method for that purpose.
  19. There's really no difference between a 'filter' and a 'search'. The filter sidebar is a effectively a search form that submits automatically every time one of the form elements changes (the submit is executed with Javascript). The index page is effectively a search results page - when no filters are set the search is fully open. Using a variable for your $pages->find() selector string it would be something like: $selector = "template=hotel, limit=5"; In the index template you look for $input->get() variables. As an example, take a single GET variable: stars=4 You check that the variable name is valid (is one of the variable names you are expecting, otherwise ignore it). You sanitize the value appropriately for that variable (in this case it should be an integer). Then you add to your selector string accordingly, narrowing down the results your selector will return... $selector .= ", $approved_var=$sanitized_value"; You will probably build up your selector string by looping over all of $input->get(). You don't need a separate template for the filter form. If you want to use the filter on several templates you can put the code in a separate PHP file and include it in your templates. Check out the Skyscrapers profile for a good example of a search template: https://github.com/ryancramerdesign/skyscrapers2/blob/master/search.php https://github.com/ryancramerdesign/skyscrapers2/blob/master/_func.php
  20. This is not the right way to get the url of a single image. When using image fields you want to select the "Formatted value" setting that suits the number of images your field is allowed to hold. I recommend you stick to two of these options: Array of items - select this when "Maximum files allowed" is set to either 0 (no limit) or greater than 1 Single item - select this when "Maximum files allowed" is set to 1 Next you need to understand what is going to be returned when you use $page->image (assuming your image field is named 'image'). If you chose "single item" then $page->image will be a single image object. If you chose "array of items" then $page->image will be an array of image objects. You don't want to ever echo an object itself (it may return some value but it's generally not good practice), but you might echo some property of the object (e.g. description) or call some method on the object (e.g. url or size). When dealing with an array of image objects you will either loop over them with foreach or you can get a single object from the array with a method such as first() or eq(). So take this code example from above: You want to get the URL of a single image in the field. If your image field is formatted as "single item" then you would do this: $image = $page->image->url; If your image field is formatted as "array of items" then you would do this: $image = $page->image->first()->url; One more thing... You are setting width and height attributes on the img tag so you should use the size() method to make sure the image is cropped to the same dimensions (or same ratio of dimensions if you are wanting a HiDPI image). $page->image->size(600,480)->url Otherwise you wont get the desired result if someone uploads an image with a different aspect ratio.
  21. @Qualtext, I tried your module in PW 3.0.45 but I couldn't get it set up properly. You'll see in the screenshot below that I have selected a parent page and an image field but the other settings are not applied automatically on save. Maybe this is due to the changes introduced to Page field settings in 3.0.45? It would be helpful if you listed the steps that users should go through in order to get the revised version of your module set up and ready to use. Something that we can refer to more easily than the video (which you could upload to YouTube and embed here in the forum BTW). The custom inputfield type seems to be unavailable?
  22. Maybe one of the parent pages has a template that has access restrictions and children inherit these? I routinely define access for all templates (because I often set restrictions on the Home template and these would otherwise flow down throughout the site). Less head-scratching that way.
  23. You could use a hook to override the decision not to show notifications in modals: $this->addHookAfter('AdminTheme::getExtraMarkup', function($event) { if($this->input->get('modal')) { $this->modules->get('SystemNotifications')->hookAdminThemeGetExtraMarkup($event); } });
  24. This one maybe?
  25. Yeah, looks like the extra markup isn't appended when the modal GET variable is present. https://github.com/processwire/processwire/blob/35df716082b779de0e53a3fcf7996403c49c9f8a/wire/modules/System/SystemNotifications/SystemNotifications.module#L113-L115
×
×
  • Create New...