Jump to content

Robin S

Members
  • Posts

    5,039
  • Joined

  • Days Won

    340

Everything posted by Robin S

  1. I whipped up a module for this:
  2. In response to a wishlist request... Field Save + Add New Adds a "Save + Add New" button when editing a field. Usage Install the Field Save + Add New module. When editing a field, click "Save + Add New" if you want to save the current field and start the process of adding a new field. Note: The button will not redirect you to "Add New" if you are performing some special action such as duplicating a field or adding a field to a template. https://github.com/Toutouwai/FieldSaveAdd/
  3. I agree with @abdus that field rendering is the solution. But if you're just wanting a tidier way of doing what you are already doing then you can rewrite it as: <?php foreach($foos as $foo): ?> <div class="foo"> <h1 class="foo__title"> <a href="<?= $foo->url ?>"><?= $foo->title ?></a> </h1> <?php if($page->headline): ?> <h2 class="page__headline"><?= $page->headline ?></h2> <?php endif; ?> </div> <?php endforeach; ?>
  4. @SamC, I don't entirely follow what you are saying, but here are a few things that might help. 1. You can remove elements in _main.php by using "pw-remove" in a template file. _main.php <div id="main"> FULL WIDTH OR SIDEBAR IN HERE </div> <div id="sidebar"> THE SIDEBAR </div> basic-page.php <!-- Remove #sidebar --> <div id="sidebar" pw-remove></div> 2. You can have as many nested ID'd or region elements in _main.php as you like, and then modify/replace any of them from your template. _main.php <region id="main"> <div class="container"> <div id="main"> FULL WIDTH OR SIDEBAR IN HERE </div> <div id="sidebar"> THE SIDEBAR </div> </div> </region> home.php <div id="sidebar"> <p>Just customise the sidebar.</p> </div> basic-page.php <region id="main"> <div class="container"> <p>Use a completely different #main on this template.</p> </div> </region> 3. The three blog posts about Markup Regions can be a bit confusing because the spec changed as the feature was developed and none of the posts cover the entire set of available keywords and syntax. Check out the comments in WireMarkupRegions.php for a more comprehensive spec. /** * Identify and populate markup regions in given HTML * * To use this, you must set `$config->useMarkupRegions = true;` in your /site/config.php file. * In the future it may be enabled by default for any templates with text/html content-type. * * This takes anything output before the opening `<!DOCTYPE` and connects it to the right places * within the `<html>` that comes after it. For instance, if there's a `<div id='content'>` in the * document, then a #content element output prior to the doctype will replace it during page render. * This enables one to use delayed output as if it’s direct output. It also makes every HTML element * in the output with an “id” attribute a region that can be populated from any template file. It’s * a good pairing with a `$config->appendTemplateFile` that contains the main markup and region * definitions, though can be used with or without it. * * Beyond replacement of elements, append, prepend, insert before, insert after, and remove are also * supported via “pw-” prefix attributes that you can add. The attributes do not appear in the final output * markup. When performing replacements or modifications to elements, PW will merge the attributes * so that attributes present in the final output are present, plus any that were added by the markup * regions. See the examples for more details. * * Examples * ======== * Below are some examples. Note that “main” is used as an example “id” attribute of an element that * appears in the main document markup, and the examples below focus on manipulating it. The examples * assume there is a `<div id=main>` in the _main.php file (appendTemplateFile), and the lines in the * examples would be output from a template file, which manipulates what would ultimately be output * when the page is rendered. * * In the examples, a “pw-id” or “data-pw-id” attribute may be used instead of an “id” attribute, when * or if preferred. In addition, any “pw-” attribute may be specified as a “data-pw-” attribute if you * prefer it. * ~~~~~~ * Replacing and removing elements * * <div id='main'>This replaces the #main div and merges any attributes</div> * <div pw-replace='main'>This does the same as above</div> * <div id='main' pw-replace>This does the same as above</div> * <div pw-remove='main'>This removes the #main div</div> * <div id='main' pw-remove>This removes the #main div (same as above)</div> * * Prepending and appending elements * * <div id='main' class='pw-prepend'><p>This prepends #main with this p tag</p></div> * <p pw-prepend='main'>This does the same as above</p> * <div id='main' pw-append><p>This appends #main with this p tag</p></div> * <p pw-append='main'>Removes the #main div</p> * * Modifying attributes on an existing element * * <div id='main' class='bar' pw-prepend><p>This prepends #main and adds "bar" class to main</p></div> * <div id='main' class='foo' pw-append><p>This appends #main and adds a "foo" class to #main</p></div> * <div id='main' title='hello' pw-append>Appends #main with this text + adds title attribute to #main</div> * <div id='main' class='-baz' pw-append>Appends #main with this text + removes class “baz” from #main</div> * * Inserting new elements * * <h2 pw-before='main'>This adds an h2 headline with this text before #main</h2> * <footer pw-after='main'><p>This adds a footer element with this text after #main</p></footer> * <div pw-append='main' class='foo'>This appends a div.foo to #main with this text</div> * <div pw-prepend='main' class='bar'>This prepends a div.bar to #main with this text</div> * * ~~~~~~
  5. Yes, the suggested fix in the GitHub issue is to replace the all the code in the "problem" block with the code in the "fix" block.
  6. That's an 11MB page you have there! And just wondering: how come the map is an image (2MB alone) instead of a real map?
  7. That's actually a different issue with a different cause. But I think I've found fixes for both issues. The new issue is here: https://github.com/processwire/processwire-issues/issues/419
  8. I tested with the core Checkbox fieldtype. You can check the fieldtype by opening the field (Setup > Fields > Your field) and looking in the Type dropdown. Not sure why it wouldn't work for you, but there is no real harm in just sticking with what you are doing (combining two PageArrays together) unless you have a huge number of children.
  9. You might find it easier to debug this and get it working by using a PW page to respond to your AJAX requests. So you create a template named "web-service" (for example) and put the code above into the template file (minus the bootstrapping line). Then create a page named "web-service" that uses this template and use this page's URL in your AJAX request. You might be able to get pagination working simply by enabling pagination for the template, or you might need to get the page number using the API and use it in conjunction with the "limit" to get the "start" for your selector. I haven't tried AJAX pagination myself.
  10. You should check out the keyword search feature in your browser. https://support.google.com/chrome/answer/95426 http://kb.mozillazine.org/Using_keyword_searches
  11. This is known as duplicate content and you want to be careful with this to avoid harming your SEO. Have a read of Google's guidelines: https://support.google.com/webmasters/answer/66359?hl=en https://support.google.com/webmasters/answer/139066 But if you want to show all the content from one page on another, one simple solution is to add a Page Reference field to your template. Then at the top of the template file: if($page->page_reference->id) $page = $page->page_reference;
  12. https://github.com/ryancramerdesign/skyscrapers2 This repo is from Ryan and it consists of the template files used in the Skyscrapers v2 demo site. There is no data with it and it is not an installable site profile. https://github.com/dadish/pw-skyscrapers-profile This repo is from @Nurguly Ashyrov and is a complete installable site profile, including the skyscrapers data and required modules. It was made by combining the data from the old v1 Skyscrapers profile with the v2 templates. The creation of the profile is mentioned in this video: https://github.com/ryancramerdesign/SkyscrapersProfile
  13. Hi @abdus, Do you know if it's possible to use this technique to add config fields such as minWidth and maxWidth to the template context for InputfieldImage? My first attempt isn't working: // Add more image config fields to template context $this->addHookMethod('InputfieldImage::getConfigAllowContext', function (HookEvent $e) { $allowables = ['minWidth', 'minHeight', 'maxWidth', 'maxHeight']; $e->return = array_merge($e->return, $allowables); }); I have a feeling that the reason this doesn't work is because those config fields are inside a fieldset. Adding the whole fieldset would be fine, but the problem is that the fieldset doesn't have a name to add to getConfigAllowContext(). Any ideas? ----- EDIT: have sussed it out. I used another hook to give names to those fieldsets. // Give names to image config fieldsets $wire->addHookAfter('InputfieldImage::getConfigInputfields', function(HookEvent $event) { /* @var InputfieldWrapper $wrapper */ $wrapper = $event->return; $f = $wrapper->getChildByName('maxWidth'); $fieldset = $f->parent; $fieldset->name = 'maxDimensions'; $f = $wrapper->getChildByName('minWidth'); $fieldset = $f->parent; $fieldset->name = 'minDimensions'; }); // Add more image config fields to template context $this->addHookMethod('InputfieldImage::getConfigAllowContext', function (HookEvent $e) { $allowables = ['maxDimensions', 'minDimensions']; $e->return = array_merge($e->return, $allowables); });
  14. For a proper draft/approval workflow there is ProDrafts. But for a simple system you can just use Lister (Pages > Find) to show unpublished pages.
  15. Have narrowed down when the issue occurs. There are two conditions needed to observe the problem: 1. A page using a template containing a repeater is created via the API and is never edited and saved in admin. This means that the parent page of the repeater items under Admin > Repeaters > repeater_field is not yet created. 2. A new repeater item is added via the API to the page created in step 1. When the parent page is created to hold the repeater item, Page Rename Options attempts to rename the parent page but this is not allowed because the parent uses a system template. The existing test for system templates in Page Rename Options fails because the page ID is 0 at this point. The fix goes here, changing a check for $p->id to $p->template: // $p->template check is because it is not available for ProcessPageAdd if($p->template && $p->template->flags & Template::flagSystem) return false; // exclude system templates eg. users etc
  16. There is a little error in your hook code: //... $field = $event->object; $href = $this->config->urls->admin.'page/add/?parent_id='.$page; $field = $this->modules->get('InputfieldButton'); //... In this hook, the event object is ProcessPageEdit, not a field. And you also overwrite $field two lines below. Rather than removing the existing button and adding a new one, you can change the text of the existing button. Here is another way it could be done: $wire->addHookAfter('ProcessPageEdit::buildFormChildren', function(HookEvent $event) { $form = $event->return; // The InputfieldWrapper on the "children" tab $ppe = $event->object; // ProcessPageEdit $page = $ppe->getPage(); // ProcessPageEdit contains a method to get the page being edited if(in_array($page->template->name, ['event_events', 'event_dates', 'event_businessvacations', 'event_specialbusinesshours'])) { $button = $form->getChildByName('AddPageBtn'); // Get the button if($button) $button->value = 'Add new event'; // Change the text } });
  17. I just installed the module brand new today. The latest version in the directory is 1.0.1.
  18. I still can't reproduce the issue. I notice that the way you are creating new repeater items does not follow the documentation to the letter: Note that the new repeater page is saved before adding it to the repeater field. Also the repeater page values are set before adding the page, but I don't think that should make a difference in the way you are doing it. But even when I do it the way you are I don't experience any problem:
  19. I just reproduced this on a clean installation. The repeater has only the title field added and all other settings are the default. Repeater field export: PageRenameOptions settings: API code: $p = $pages(1029); // a page that has the repeater in its template $p->of(false); $r = $p->test_repeater->getNew(); $r->title = "Repeater item"; $r->save(); $p->test_repeater->add($r); $p->save();
  20. @oma, you might be exceeding PHP's max_input_vars limit. http://php.net/manual/en/info.configuration.php#ini.max-input-vars You could try raising the limit to 2000 or higher in php.ini.
  21. @bernhard, could you show the code you are using to add pages and repeater items? I am trying to reproduce the problem but I'm not able to. I didn't know setAndSave() supported adding items to repeater fields - how are you using it for that? And if you are creating pages and adding repeater items in one operation, are you saving the page before adding the repeater items? E.g. $p = new Page(); // ... $p->save(); // are you saving here? $r = $p->your_repeater->getNew(); // ... $p->save();
  22. Hi @adrian, I found that the "Enable for API" option prevents Repeater pages being added via the API (for repeaters that contain a title field at least). At this point... $r = $page->my_repeater->getNew(); ...I get the error:
  23. Probably obvious, but if you want to lock only repeater items that have the checkbox checked then you would add a conditional for that in the hook that BitPoet suggested. if($repPage->your_checkbox) { $event->return->collapsed = ($event->return->collapsed === Inputfield::collapsedNo || $event->return->collapsed === Inputfield::collapsedNoLocked) ? Inputfield::collapsedNoLocked : Inputfield::collapsedYesLocked; }
  24. That is really weird. Not sure what could cause that, but some things to try: Add "include=all" to the selector. Add "check_access=0" to the selector. If there is any access control set for the repeater field, select the "Make field value accessible from API even if not viewable" option. Test the selectors in a template file to rule out any issue with the Tracy console.
  25. @mel47, you must use the "Custom PHP code" option, adding a hook to /site/ready.php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'event_date') { // Where 1234 is the ID of the settings page $event->return = $event->pages->get(1234)->date_selection; // The selectable pages is the value of the "date_selection" field } });
×
×
  • Create New...