-
Posts
4,928 -
Joined
-
Days Won
321
Everything posted by Robin S
-
The path must be /site/ready.php Create a new PHP file "ready.php" in the "site" directory. Save the following as the contents of this file: <?php $pages->addHookAfter('saveReady', function (HookEvent $event) { $page = $event->arguments(0); if($page->template != 'blog-post') return; // Only for the blog-post template if(!$page->id) return; // Skip pages that are brand new and aren't yet populated with data // If the page name doesn't start with the page id if(strpos($page->name, (string) $page->id) !== 0) { // Prepend the page id to the page name $page->name = $page->id . '-' . $page->name; } }); Adjust the name of the blog post template within the hook if needed.
- 46 replies
-
- blog post
- change path formatting
-
(and 1 more)
Tagged with:
-
Nowhere does the documentation say that "Name format for children" supports the string "id". The (unfortunately very brief) documentation for the feature says that it supports the string "title", or a date format string. When you insert "id" in the setting field PW attempts to interpret it as a date format. If you need something beyond what the feature provides you could try kixe's module, or use a hook.
- 46 replies
-
- blog post
- change path formatting
-
(and 1 more)
Tagged with:
-
Page IDs are not random, and they do auto-increment. If you check the "pages" table in phpMyAdmin you will see that the ID column is an auto-incrementing INT type. You'll also notice that rows (pages) in the table have sequential IDs. But the IDs increment site-wide for all pages, not separately or specifically for your blog post pages. So if you add some non-blog pages in between blog posts then the IDs for your blog posts will not be sequential. Deleting pages will also create gaps in the ID sequence. But all of this is completely normal on a system like this, and I can't see how it affects anything you might need to do with a blog post. Perhaps you could explain what the specific problem is that you are trying to overcome by inserting IDs in the page names.
- 46 replies
-
- blog post
- change path formatting
-
(and 1 more)
Tagged with:
-
What is your purpose for finding the pages within CKEditor? To link to them? In that case it takes a single click on the link button in the toolbar, then you have autocomplete in the "Link to URL" field.
-
Nothing extra is needed to achieve this. If you create a page that has the same title as another page under the same parent then by default PW will automatically add a digit to the end of the page name to make it unique. Unless you have a need for something different it's best to just leave it at that. But if you want to prepend the page id to the page name you can do it with a hook in /site/ready.php: $pages->addHookAfter('saveReady', function (HookEvent $event) { $page = $event->arguments(0); if($page->template != 'blog-post') return; // Only for the blog-post template if(!$page->id) return; // Skip pages that are brand new and aren't yet populated with data // If the page name doesn't start with the page id if(strpos($page->name, (string) $page->id) !== 0) { // Prepend the page id to the page name $page->name = $page->id . '-' . $page->name; } });
- 46 replies
-
- 2
-
- blog post
- change path formatting
-
(and 1 more)
Tagged with:
-
[solved] $session incorrectly storing string from $page var
Robin S replied to psy's topic in General Support
Most likely explanation is that the page path or ID that you are saving to session is correct, and that it simply is the 404 page that is being loaded. Maybe you have removed view access for the guest role on one or more templates, and have the "Show a 404 page" option selected? Incidentally, an alternative to what you are doing in _init.php is to select the option "Redirect to another URL" to redirect to your login page, and pass the ID of the page that the user attempted to access in a GET variable. So something like... /login/?return={id} ...then you look for the return variable in your login template and redirect back to that page after login. -
How to state separately a PW hook that uses the 'use' PHP construct?
Robin S replied to LAPS's topic in Getting Started
Not entirely sure about the following, so would be glad to hear from anyone who understands this better. @ryan? I think you must pass in any external variables to a named hook function as part of the $options array. See this line in the HookEvent class: @property array $options An optional array of user-specified data that gets sent to the hooked function. The hook handling method may access it from $event->data. Also includes all the default hook properties. So you would assign a custom key/value to the $options array by reference. An example: $colour = 'red'; $options = array(); $options['colour'] = &$colour; // assign by reference $wire->addHookAfter('Pages::save', null, 'hookFunction', $options); function hookFunction(HookEvent $event) { $opts = $event->options; $opts['colour'] = 'green'; // $colour is now 'green' // ... } -
Can anyone tell me the difference between the following pieces of code
Robin S replied to SamC's topic in General Support
It's the WireData::and() method. Was a new one to me too. -
A Map Marker field has several subfields. You would pick one of these subfields as a basis for determining whether or not you consider the field to be populated: 'lat' is probably a good one. $items = $pages->find("template=walk_segments, start_town.marker.lat!='', end_town.marker.lat!='', sort=title");
-
You could do this with URL segments in the template for the /blog/ page. How to use URL segments
- 46 replies
-
- 1
-
- blog post
- change path formatting
-
(and 1 more)
Tagged with:
-
is it possible to restrict the page level of drag & move of a page ?
Robin S replied to adrianmak's topic in General Support
-
You can search for the text string that makes up the start of the tag (to allow for varying attributes). // Get fields with TextformatterHannaCode applied $hanna_fields = array(); foreach($fields as $field) if(is_array($field->textformatters) && in_array('TextformatterHannaCode', $field->textformatters)) $hanna_fields[] = $field->name; // Implode for use in selector string $hanna_fields = implode('|', $hanna_fields); // Find pages with a given Hanna tag $has_hanna = $pages->find("$hanna_fields*=[[your_tag");
-
Good solution, thanks.
-
Stoked about the new documentation site! I love it even more with the text size zoomed to 125% In due course it would be great to add a section about barDumpLive() / bdl() - I've never been clear on when it's okay to use this and when it should be avoided due to the dumped variable getting mixed up. I use it from time to time and when there is a variable mix-up it's usually pretty obvious, in which case I switch to bd() with max depth and max length options included. Although I still worry there might be situations where the mix-up is more subtle and could lead to confusion. Related to this: what do you think about adding a new shortcut method for "big" bardumps? This could have options in the module config for max depth and max length. Just so there's a quick way to do a bardump where you need greater nesting depth and string length than with the standard bd(). I have added a custom shortcut in my IDE for inserting a bd() with max depth and length options, but it would be cool to have something like a "bdb()" method in Tracy (until the barDumpLive thing is resolved anyway).
-
Not sure. It works for me in PW 3.0.88. Seems like it could be a Javascript error - check your browser console to see if that reveals any issues.
-
Setup > Templates > my-template > Advanced > Label for Children Tab
-
I can confirm the problem. When the inputfield is inside a repeater item the module tries to open the link modal for the repeater page, but non-superusers do not have direct access to repeater pages. The core link modal (opened from CKEditor) does not have this problem because in the case of being inside a repeater item it opens the link modal for the container page instead. You can apply the same logic to this module by editing InputfieldAssistedURL.module, changing line 62... $btn->attr('data-page-id', $this->page->id); ...to (edit: there could be multiple nested repeaters, so best to borrow the code from ProcessPageEditLink)... $page = $this->page; $n = 0; while(wireInstanceOf($page, 'RepeaterPage') && ++$n < 10) { $page = $page->getForPage(); } $btn->attr('data-page-id', $page->id);
-
That was my initial thought too, but then I realised that this module by definition applies to situations where there is only zero or one child of that template under a parent. So that selector is at most going to return one page.
-
This is a setting for Page Reference fields. It appears when you select "Custom format (multiple fields)" in the "Label field" dropdown. You would use something like {default_instrument.title} as part of the custom format, so you can see what the default instrument is for each player within the Page Reference inputfield and therefore if you need to override it. But bear in mind that if you do not manually select an instrument for each player and a player later changes their default instrument then all the concerts they have performed in will show the new default instrument, which wouldn't be good.
-
This approach works for the backend too. $wire->addHookBefore('InputfieldSelect::render', function (HookEvent $event) { $inputfield = $event->object; $field = $inputfield->hasField; if(!$field || $field->type != 'FieldtypeOptions') return; if($field->required) $inputfield->options = array('' => 'Choose One') + $inputfield->options; });
-
@adrian, you are right that the issue is with InputfieldSelect. I added a note to that effect at GitHub. Until it is fixed this seems to be an okay workaround: $wire->addHookBefore('InputfieldSelect::render', function (HookEvent $event) { $inputfield = $event->object; $field = $inputfield->hasField; if(!$field || $field->type != 'FieldtypeOptions') return; if($field->required) $inputfield->required = false; }); The inputfield is still treated as required in Page Edit.
-
Yeah, it's not a solution. There is an open GitHub issue for this: https://github.com/processwire/processwire-issues/issues/349
-
Glad you have it working. Just a couple of things to be aware of if you do it this way: 1. Depending on how many Walk Variations are within a Walk, and how many Walk Segments are within a Walk Variation, you could end up loading way more pages into memory than you actually need (you only need the Walk pages). But if the number of pages isn't large then this could be fine. 2. If there are a lot of Walks in the continent, and for efficiency you want to paginate them into groups of 20 for example, this becomes difficult. Because you don't know how many Walks will result from any set of Walk Segments until you loop over them.
-
Sounds very useful. Please share your module fork when you're ready.
-
Not quite sure what you mean here. You somehow edited the Map Marker fieldtype to include a continent subfield? Or do you just mean you added a field Continent to the Walk Towns template? It might depend a bit on what type of field Continent is, but something like this should work: $walks_in_africa = $pages->find("template=walk, (children.children.start_town.continent=Africa), (children.children.end_town.continent=Africa)");