-
Posts
4,931 -
Joined
-
Days Won
321
Everything posted by Robin S
-
Try: $template_has_title = $fields->get('title')->getFieldgroups()->implode('|', 'name'); $page_has_title = $pages->find("template=$template_has_title, has_parent!=2"); If you just want the count of the pages rather than the pages themselves you can do: $count = $pages->count("template=$template_has_title, has_parent!=2");
-
Image field: check if first image is under a certain width
Robin S replied to OpenBayou's topic in API & Templates
A way you could do this without any code: 1. Create one image field for the first image and one image field for the second/subsequent image(s). 2. Set "Min width for uploaded images" to 200 for the first image field. Incidentally, your original post says that the first image should be under 200 pixels wide, but that doesn't make sense so I assume you mean over 200 pixels wide. 3. Make both image fields "required". -
When deciding whether or not to use a parent-child structure to create a relationship, the questions I ask are: 1. Is this relationship a primary (very important) relationship? 2. Do I want the relationship to be revealed in the page URL? (Note that other types of relationship may still be represented in a URL via the URL Segments feature) 3. Is the relationship exclusive? (i.e. may the child only belong to a single category/parent - you want to avoid a situation where the same page would appear under more than one parent). If the answer to any of these is "no" then I use a Page field for the relationship rather than a parent-child structure.
-
If you just want a notification that a page is currently being edited by another user (like the default behaviour of Page Edit Soft Lock) then the optional core System Notifications module also has that feature. But if you want a "hard lock" option then I think Page Edit Soft Lock is the only option currently.
-
Instead of... foreach($post->children("sort=-publish_date") as $child) { ...try... foreach($post->children()->sort("-publish_date") as $child) { I assume "publish_date" is a custom field you have added to your template - otherwise perhaps you are looking for "created". More likely "published". What's the deal with all the opening/closing PHP tags?
-
There was a typo in the hook code I posted: should have been "parents" and not "parent". This should work... $nav = $modules->get('MarkupSimpleNavigation'); $nav->addHookAfter('getItemString', function(HookEvent $event) { $item = $event->arguments('page'); // if the item has more than one parent then it is a subpage if($item->parents->count() > 1) { $event->return = "<a href='{$item->parent->url}#{$item->name}'>$item->title</a>"; } }); // define your options array if needed and render your menu If not please post your MarkupSimpleNavigation code.
-
How to: pagination with different limit for first page
Robin S replied to Raymond Geerts's topic in General Support
Sounds like a good solution, but renderPager() will show a different number of pages on the first page than the others (because it is dividing 100 by 8 instead of 10). So you may need to use a custom pager to get around this. -
The hook example I gave will work, but you need to make sure the 'if' condition matches the child pages you are rendering inside their parent page. if($item->parent->count() > 1) {... If this condition isn't matching your child pages (I can't tell on your site - looks like it isn't installed in the hosting root) then change it to something that does. Like, maybe they have a particular template: if($item->template->name === 'my_template') {... Also, it looks like your container divs are using the page title for the ID when they should use the page name: <div id="Lieferservice" class="titelblock anchor"> ...should be... <div id="lieferservice" class="titelblock anchor"> Maybe it will help if you post your MarkupSimpleNavigation code.
-
[Solved] Search function AND/OR and sorting of the results
Robin S replied to rash's topic in Getting Started
Not if PageArray 2 contains some of the same pages as PageArray 1. If you want to maintain the sort order make sure the PageArray you are importing has only unique pages not in the other PageArray. For example: $pa2->removeItems($pa1); $pa1->import($pa2); Regarding the %= operator, note that if there are multiple words in the search string then the entire string must appear in that exact order in the field(s) being searched. See this solution for allowing the words in any order/location: -
FYI, on Windows this issue seems to be specific to Chrome (or perhaps Webkit). Firefox and IE can delete heading text without affecting subsequent elements.
-
You could write a simple textformatter module to replace instances of "my-simple-class" with "my-long list-of class-names".
-
That is insane. Maybe time to move to a new host.
-
URL Segment showing 404 when i tried to open page in browser
Robin S replied to Junaid Farooqui's topic in Dev Talk
Good to know - I had read on Stack Overflow that it was an efficient way to return the string of characters occurring before a substring but never tested it. Lets try that again... At the top of template files where child pages need the custom ".html" URLs: if(empty($options['pageStack']) && $input->urlSegment1) { $name = $sanitizer->pageName(rtrim($input->urlSegment1, '.html')); $p = $pages->findOne("parent=$page, name=$name"); if($p->id) { echo $p->render(); $this->halt(); } else { throw new Wire404Exception(); } } In /site/ready.php: $this->addHookAfter('Page::path', function($event) { $page = $event->object; $tpls = ['basic_page', 'some_template']; // define template names if(in_array($page->template, $tpls)) { $return = rtrim($event->return, '/'); // remove trailing slash if present $event->return = $return . '.html'; } }); Not that I think any of this is a good idea. Better to tell the SEO team that there is no reason to prefer /my-page.html over /my-page/.- 6 replies
-
- 2
-
- seo
- urlsegment
-
(and 1 more)
Tagged with:
-
URL Segment showing 404 when i tried to open page in browser
Robin S replied to Junaid Farooqui's topic in Dev Talk
For the URL /products/product-one.html, as kongondo says ".html" will not be recognised a valid URL segment in the template for "product-one". But "product-one.html" would be a valid URL segment in the template for "product". So you would need to enable URL segments for every template and at the start of every template file you could have something like this: if($input->urlSegment1) { $name = strtok($input->urlSegment1, '.html'); $p = $page->children->get("name=$name"); if($p->id) { echo $p->render(); $this->halt(); } else { throw new Wire404Exception(); } }- 6 replies
-
- 1
-
- seo
- urlsegment
-
(and 1 more)
Tagged with:
-
Assuming you are rendering your child pages in container elements with an ID matching the page name: $nav = $modules->get('MarkupSimpleNavigation'); $nav->addHookAfter('getItemString', function(HookEvent $event) { $item = $event->arguments('page'); // if the item has more than one parent then it is a subpage if($item->parents->count() > 1) { $event->return = "<a href='{$item->parent->url}#{$item->name}'>$item->title</a>"; } }); // define your options array if needed and render your menu You may want to block direct access to the subpages, in which case see this thread:
-
Disallow accessing page using template via it's url
Robin S replied to LimeWub's topic in General Support
A couple more options... At the top of the file for the template of pages you are including inside another page: if(empty($options['pageStack'])) throw new Wire404Exception(); if($page->url == $_SERVER['REQUEST_URI']) throw new Wire404Exception(); A related thread: -
-
As a general rule, you can copy any PW module from /wire/modules/ to /site/modules/ if you want to customise it. When you do a Modules > Refresh you will see a notice... Session: Module "SomeModule" has multiple files (bold file is the one in use). Click here to change which file is used ...and you can enter the module settings to switch between the version in /wire/ and the version in /site/.
-
You can certainly create your own plugin and toolbar button for CKEditor. PW doesn't get in the way of that, but it's something that you would learn about in the CKEditor docs rather than the PW docs. You can place your plugin in /site/modules/InputfieldCKEditor/plugins/ and then select it for CKEditor fields in the field settings on the Input tab. Or if you want to include your CKEditor plugin in a PW module you could have a look at how HannaCodeHelper does it. You will need to include the name of the toolbar button in the CKEditor Toolbar section of the field settings. Copy /wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/ to /site/modules/InputfieldCKEditor/plugins/pwlink/ and make your changes there.
-
He talks about the separation of concerns... ...and MVC is a popular pattern that enforces that. But they're not exactly the same thing, for sure.
-
I think this new approach is similar to template engines in one respect: the idea of extending a named block. This feature is present in template languages like Smarty and Twig and I for one find that feature very useful. I don't see any other similarities to template engines though. What would be your idea of misuse of this new strategy? If you mean it allows (encourages?) developers to not follow the MVC pattern then I don't see this as a big issue. There is no cardinal rule: "Thou shalt use MVC in all projects" - it depends very much on the type of developer you are and the type of project you are working on. When Ryan says... ...I take this to mean people who are new to PHP development in general. People who have a design background, or those used to a drag-and-drop interface, or who have previously worked only with static HTML. If someone has a lot of PHP experience I doubt they would find anything about PW difficult to understand - more like a breath of fresh air. And people who are new to PHP development are not going to be: building large, complex web projects working on long-lived projects that will be handed over to future developers collaborating on a project with other developers in a team For any of these I totally see the value of MVC. But if you are a newbie working on <10 page brochure websites you do not need MVC.
-
add page selector to module configuration
Robin S replied to Marc's topic in Module/Plugin Development
The error is visible if you install Tracy Debugger. -
Not sure how you got the rectangular thumbnails - mine are always square when rendered inside a PageTable, regardless of the the image field settings. Which isn't a bad thing in this case because the solution involves overriding the JS image sizing with CSS and you're not going to be able to preserve the aspect ratio for each image. These custom CSS settings (use AdminCustomFiles or AdminOnSteroids) gave the result that follows. .Inputfield_pt_thumbnails .InputfieldImage .gridImage__overflow img { height:100%; } .Inputfield_pt_thumbnails td:nth-child(2) .InputfieldImage .gridImage__overflow { height:260px !important; width:260px !important; } .Inputfield_pt_thumbnails td:nth-child(3) .InputfieldImage .gridImage__overflow { height:100px !important; width:100px !important; } There is no way to identify individual image fields from the markup so you have use nth-child() selectors to target table columns. Portrait-format images will not fill their frames.
-
add page selector to module configuration
Robin S replied to Marc's topic in Module/Plugin Development
The inputfield value is not saved correctly because config you are trying creates an error: PHP Notice: Object of class ProcessWire\Page could not be converted to int in ...\modules\Process\ProcessModule\ProcessModule.module:1287 So it seems that the inputfield you have created is returning a page object when what is expected is a page id. One solution is to create the options you want to make available in the inputfield: class ProcessHelloConfig extends ModuleConfig { public function __construct() { $items = $this->pages->find("parent=1"); $page_options = []; foreach($items as $item) { $page_options[$item->id] = $item->title; } $this->add(array( // Text field: greeting array( 'name' => 'greeting', // name of field 'type' => 'text', // type of field (any Inputfield module name) 'label' => $this->_('Hello Greeting'), // field label 'description' => $this->_('What would you like to say to people using this module?'), 'required' => true, 'value' => $this->_('A very happy hello world to you.'), // default value ), // Radio buttons: greetingType array( 'name' => 'greetingType', 'type' => 'radios', 'label' => $this->_('Greeting Type'), 'options' => array( // options array of value => label 'message' => $this->_('Message'), 'warning' => $this->_('Warning'), 'error' => $this->_('Error'), ), 'value' => 'warning', // default value 'optionColumns' => 1, // make options display on one line 'notes' => $this->_('Choose wisely'), // like description but appears under field ), // My custom test field array( 'name' => 'myTest', 'type' => 'select', 'label' => $this->_('Test'), 'options' => $page_options, ), )); } } BTW, if you want to allow the user to select any page from the tree you can use the Page List Select inputfield: // My custom test field array( 'name' => 'myTest', 'type' => 'PageListSelect', 'label' => $this->_('Test') ) -
I think a separate mobile website is an outdated approach and device sniffing will be both unreliable and require more maintenance. I would highly recommend a single responsive design, but if you're sure you want to pursue separate templates for mobile devices then you could select templates by domain as suggested here... ...or use the same approach but test for device using Mobile Detect.