Jump to content

BillH

Members
  • Posts

    256
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by BillH

  1. The field page2use4homepage will return a null page (id = 0) if no page is selected, which might be confusing things.

    I haven't tested, but I'd suggest using:

    (($page->id == 1) && ($page->page2use4homepage->id != 0))

     

  2. This happened to me once when I moved a site to a new server and accidentally used details for remote access to the first server for dbHost. Took me a while to figure it out!

    There can be various sorts of caching on the server, which may have been set up as a default by the hosting company without you being aware of it. They don't usually cause problems, but they might. What sort of server setup do you have?

  3. I suggest that first you find the error in the HTML as delivered to the browser, and then work out the source of the error.

    View the source of the page or your browser's developer tools ("Inspect"). If you can't work it out, try an HTML validator (e.g. https://validator.w3.org/).

    An <a> element within a <p> is certainly OK.

    With any luck, once you know what the error is, the cause will be reasonably clear. As a total guess, I suspect it'll be something in your template file.

    • Like 1
  4. Hadn't read your original post properly ?

    Just another thought: do you need to use datetime fields?

    If there are a fairly limited number of possible start and end times during the day, you could set up pages for each time, and select using page reference fields. The time pages could have fields with formatted and numerical representations of the time.

    To find pages in a time range, you'd find the relevant time pages, and then use those to find the courses, something along the lines of this:

    $startTimes = $pages->find("template=times, time>=1200, time<=1400");
    $endTimes = $pages->find("template=times, time>=1500, time<=1700");
    $courses = $pages->find("template=course, start_time=$startTimes, end_time=$endTimes");

    Not tested, but I think it'd work.

  5. I think the information you need is in this post:

    So, in brief, the values in a selector should be UNIX timestamps.

    Note that, in a template, if you get a date from a field it will be formatted according to the settings for the field, but you can use $page->getUnformatted('your_date_field') if you need the timestamp.

     

     

  6. When you say you have deleted the cache, do you mean your browser cache or PW cached files?

    If you haven't cleared PW cached files, they're at Site > Assets > Cache, and it's probably just the ones in Page that might be relevant. You can simply delete everything in the folder.

    Alternatively, you can clear cached page output by going to Modules > Core > PageRender > Settings.

    I don't know if this will help, but it's worth a try.

  7. You need to check whether there's something in the end date field.

    Then, if you're going to use the value in a function, you need to give it a suitable value if there's nothing in the field. For example:

    if ($single->End_date) {
        $end = date('d. m. Y', $single->getUnformatted('End_date'));
    } else {
        $end = date('d. m. Y', 0); // This would be 01.01.1970, but you might want something in the future
    }

    I also note that you are getting the unformatted dates from the fields and then formatting them again with the date() function. As you are just comparing values (at least in the code you have posted), you could simply use the values from the fields, or the unformatted value if it's easier to work with UNIX times.

    And you have $today == $start twice in your first 'if' condition!

    • Like 1
  8. Trying to manage folders yourself would be seriously hard work and difficult, as discussed in this post:

    If a high proportion of your pages don't have images, and the total number of images is well under half the number of pages, you could take a one-image-per-page approach, with each image held in sub-page.

    A couple of modules that might help with this are:

    https://modules.processwire.com/modules/repeater-images/

    https://modules.processwire.com/modules/process-visual-page-selector/

     

  9. The idea from @Ivan Gretsky of using template tags (which are on the Advanced tab of Edit Template) seems like a really good one.

    An approach to searching for tags on templates is here:

    Another possibility would be to prefix each relevant template name (e.g. "prefix-templatename") and then find using the "starts with" operator:

    $foundPages = $pages->find("template^=prefix");

    But I think the tags approach would probably be better – more flexible, and organises things nicely on the Templates page in the admin.

    • Like 3
  10. Thanks for the suggestion @Robin S

    Seems like a nice way of doing it. There no risk (however remote) of accidentally replacing something that shouldn't be replaced, and it's more resilient to change. And I suspect there are going to be more requests to change labels and the like in future, so this could be a good approach for keeping things well organised.

  11. Hanna Code may well be a good approach.

    Another option, if there's some way to logically deduce what classes should be added based on how an image is included in CKEditor or the like, would be to use PHP in the template to add the classes.

    Or if this was applicable to multiple fields or templates, you could look into writing a textformatter module to apply the classes (not difficult if you start by copying a simple one).

    If each image will always be handled in the same way, an option might be to use image tags (https://processwire.com/docs/fields/images/) and then use PHP in the template (or a textformatter) to apply classes based on the tags.

    Note that it's probably the CKEditor Advanced Content Filter (ACF) that's stripping out the classes - you could test by turning it off on the Input tab for the field. If it is ACF, then look at Extra Allowed Content (a bit further down on the Input tab). But you probably don't want to be editing the HTML by hand anyway.

  12. Many thanks @dragan, that works fine.

    The View tab is very slightly complicated by having a dropdown menu, so in case it's useful for anyone, here's a version that deals with that (changes "View" to "Preview"):

    wire()->addHookAfter("ProcessPageEdit::execute", function($event) {
    
        $render = $event->return;
        $template_name = "basic-page"; // Change to the relevant template name
    
        if (false !== strpos($render, "template_{$template_name} ")) {
            $render = str_replace("View<span id='_ProcessPageEditViewDropdownToggle'", "Preview<span id='_ProcessPageEditViewDropdownToggle'", $render);
            $render = str_replace("Exit + View</a>", "Exit + Preview</a>", $render);
            $event->return = $render;
        }
    
    });

    Replacing just "View<span" would probably be enough, but perhaps there's a tiny risk it'd be in a rich text field as well.

  13. I'm trying to change the name of the View tab (client request) and can't work out how to get at the label property.

    The closest I've got to it is the url property.

    I've tried many things, including this:

    $this->addHookAfter('ProcessPageEdit::buildFormView', function($event) {
        
        $arguments = $event->argumentsByName();
        bd($arguments);
        // Result: only 'url'
        
        $viewTab = $event->return;
        bd($viewTab);
        // Result: null
    
    });

    And this:

    $this->addHookAfter('ProcessPageEdit::buildForm', function($event) {
        
        $form = $event->return;
        $viewTab = $form->find("id=ProcessPageEditView")->first();
        bd($viewTab);
        // Result: false
    
    });

    Does anyone know what I should be doing?

  14. Your approach seems a good one.

    I don't know how you've configured things, but in similar circumstances I have usernames based on email addresses. As ProcessWire usernames are page names (mostly this just means replacing the @ with a hyphen), the following works for me:

    $email = $this->sanitizer->email($input->post->username);
    $username = $this->sanitizer->pageName($email);

    Sanitizing the email address might be a small improvement to your approach.

     

  15. For a basic approach:

    $breadcrumbs = $page->title;
    foreach($page->parents() as $parent) {
        $breadcrumbs = "<a href='{$parent->url}'>{$parent->title}</a> / " . $breadcrumbs;
    }

     

    • Like 6
×
×
  • Create New...