Jump to content

PWaddict

Members
  • Posts

    908
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by PWaddict

  1. 3 minutes ago, gmclelland said:

    Probably a silly question, but do you have Tracy enabled on the frontend? 

    tracy-debug.jpg.5134601a5417fdc1d78cd9bfe13f8f9c.jpg

    I haven't changed anything on module settings and yes it's enabled since I already can see the normal bar.

  2. 25 minutes ago, adrian said:

    Are you using a JS framework?

    You need to make sure the X-Requested-With header is sent so that PHP (and therefore Tracy) can recognize it as an AJAX call. jQuery does this by default, but other frameworks may not, eg Angular.

    In pure/vanilla JS, you can do:

    
    xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");

     In Angular you can do:

    
    $http.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";

     

    I'm using JQuery and on frontend I can see the header X-Requested-With: XMLHttpRequest but there is no AJAX bar.
    On backend there is no X-Requested-With: XMLHttpRequest header but I can see the AJAX bar.

  3. 2 minutes ago, adrian said:

    The AJAX bar displays automatically when there has been an AJAX request - you can see this behavior when viewing the Page Tree in the PW admin, or triggering sub items from any of the admin menus, or any AJAX calls you make on the frontend.

    You should also see "Redirect" bars when there has been a redirect call.

    Do you not see any of these?

    Ah yes only on backend I can see the AJAX one. On frontend I can't see it even though the entire site is based on AJAX.

  4. 3 minutes ago, adrian said:

    Sure - just check out the RequestInfo panel on the AJAX bar and open up the Input POST section.

    Does that get you what you want?

    There are more than 1 bars??? How can I view the AJAX one?

  5. 41 minutes ago, adrian said:

    I don't know - you tell me ?

    I just took a very quick look and the basic functionality seems ok. Could you point me to what you are having issues with?

    I'm still using the 3.0.110. I've read about the changes on page names on 3.0.111 and that's why I asked if it affects the module.

  6. The following hook should do what you want. It's based on old @Soma's post. All you have to is to edit $myslug with your random hash generator.

    $wire->addHookBefore("Pages::saveReady", function(HookEvent $event) {
    
      $page = $event->arguments[0];
      if ($page->template->name != 'news-article') return;
    
      foreach ($this->languages as $lang) {
    
        $lname = $lang->isDefault() ? '' : $lang->id;
        $default = $this->languages->get("default");
        $myslug = '-myslug';
    
        if ($page->title->getLanguageValue($lang)) {
          $page->set("name$lname", $page->title->getLanguageValue($lang) . $myslug);
        } else {
          $page->set("name$lname", $page->title->getLanguageValue($default) . $myslug);
        }
      }
    
    });

     

    • Like 2
  7. @kixe The 175 line of the module is causing the issue:

    if (wire('fields')->get($format) && wire('fields')->get($format)->type instanceof FieldtypeOptions) $value = $page->get($format)->get('value|title');

    I had to change this to this in order to get the title of the options field:

    if (wire('fields')->get($format) && wire('fields')->get($format)->type instanceof FieldtypeOptions) $value = $page->get($format)->title;

     

    Additional languages for the options field are ignored cause I'm only getting the default one for all page names.

    Please check it out and update the module. Thanks.

  8. @kixe I want to use an Options field as part of the pagename but I don't get anything. On the Name format for children I tried with: title my_options_field and with title my_options_field.title but I only get the pagename from the title field.

    • Like 1
  9. Here is how I did it:

    $wire->addHookAfter("Pages::save", function(HookEvent $event) {
    
      $page = $event->arguments[0];
      if($page->template->name != 'my-template') return;
    
      $admin_page_name = wire("pages")->get(2)->name;
      $repeater_id = wire("fields")->get('my_repeater_field')->id;
    
      $empty_items = $pages->find("template=repeater_my_repeater_field, my_text_field='', parent=/{$admin_page_name}/repeaters/for-field-{$repeater_id}/for-page-{$page->id}/, include=all");
    
      if(count($empty_items)) {
    
        foreach($empty_items as $empty_item) {
        $page->of(false);
        $page->my_repeater_field->remove($empty_item);
        $page->save();
      }
    }

     

    • Like 3
  10. I would like to auto remove repeater items if a text field inside repeater item is empty.

    The below code placed inside the template removes the specific repeater items when someone visits the page. How can make it work in a Hook when the editor saves the page on backend?

    $admin_page_name = $pages->get(2)->name;
    $repeater_id = $fields->get('my_repeater_field')->id;
    
    $empty_items = $pages->find("template=repeater_my_repeater_field, my_text_field='', parent=/{$admin_page_name}/repeaters/for-field-{$repeater_id}/for-page-{$page->id}/, include=all");
    
    foreach($empty_items as $empty_item) {
    	$page->of(false);
    	$page->my_repeater_field->remove($empty_item);
    	$page->save();
    }

     

  11. Try the below but on the template enter the name of the repeater template. If you go to "Setup > Templates > Filters > Show system templates? > Yes" you'll find that your repeater field has a template like this: repeater_your_event_repeater:

    $upcoming_dates = $pages->find("template=repeater_your_event_repeater, agenda_datum>=$today, sort=agenda_datum, limit=3");

     

  12. 10 minutes ago, tooth-paste said:

    @PWaddict: Thank you, but can I place the code on a different page(homepage)? I tried the following code but it does not work.

     

    Sorry my mistake. The selector code if placed on another page must be $pages->find. Try this:

    $upcoming_dates = $pages->find("template=your_event_template, agenda_datum>=$today, sort=agenda_datum, limit=3");

     

  13. @wbmnfktr Repeater items are actually pages too.

    @tooth-paste Here is how you can do it:

    <?php if(count($page->event_repeater)) {
      $today = strtotime("today");
      $upcoming_dates = $page->event_repeater->find("event_date>=$today, sort=event_date");
    
      if(count($upcoming_dates)) {
        
        foreach($upcoming_dates as $upcoming_date) {
    
    ?>
    
    <div>...</div>
    
    <?php } 
      } 
    } ?>

     

    • Like 2
  14. To easily add rel="next" and rel="prev" tags for pagination in head section insert the following hook to your site/ready.php:

    $wire->addHookAfter('Page::render', function(HookEvent $event) {
    
      $page = $event->object;
      if($page->template == 'admin') return;
    
      $tags = '';
      $config = wire('config');
    
      if($config->urls->httpNext) {
        $tags .= "<link rel='next' href='{$config->urls->httpNext}'>";
      }
    
      if($config->urls->httpPrev) {
        $tags .= "<link rel='prev' href='{$config->urls->httpPrev}'>";
      }
    
      $event->return = str_replace("</head>", $tags . "</head>", $event->return);
    
    });

     

    • Like 7
    • Thanks 2
×
×
  • Create New...