Jump to content

Tyssen

Members
  • Posts

    354
  • Joined

  • Last visited

Posts posted by Tyssen

  1. 51 minutes ago, Robin S said:

    But if the repeater items are to be output among the matrix items then I'm not sure why the repeater exists as a separate field. Wouldn't it be better to just have a matrix field alone and replace the repeater with a matrix type?

    Every page is going to use the repeater matrix but only the home page is going to need to have the repeater as well so I was trying to find a solution that would keep the repeater option out of the matrix field, but I guess it's not that big a deal really, so I'll go with that.

  2. I have two fields on a page, one a normal repeater and the other a repeater matrix. What I want to be able to do is allow the content editors to choose to insert the content from the normal repeater field in between other content in the repeater matrix field.

    I thought I could insert some text into the repeater matrix and then do a conditional in my templates to check for that string and insert the other field's output there.

    My template looks like this at the moment:

    home.php

    $inserted = 'Data from the normal repeater field created with a foreach loop';
    
    $page->render('repeater_matrix_field');

    repeater_matrix_field.php

    foreach($value as $item) :
      echo $item->render();
    endforeach;

    matrix_body.php

    if($page->heading=='Replace this') :
      echo $inserted;
    else:
      echo '<h2>'.$page->heading.'</h2>';
    endif;

    I don't get any output I guess because the $inserted variable doesn't get passed from home.php to the other templates.

    So is there a way to do that, or is there a better way to achieve what I'm trying to do?

  3. I have a series of pages that use a repeater field and I want to fetch 3 random rows from each repeater from 5 specific pages, so that I'll have a total of 15 items output, but then also randomise the output so that items from the same repeater field aren't next to each other.

    Originally I had 

    $selected_pages = $pages->getById([1049,1053,1055,1059,1152]);
    		foreach($selected_pages as $selected_page) :
    			foreach($selected_page->repeater_field->getRandom(3) as $item) :
    				Output
    		endforeach;
    endforeach;

    That gave me the pages randomised, but also gave me the items from each page's repeater next to each other.

    So then I tried

    $selected_pages = $pages->get("id=1049|1053|1055|1059|1152")->repeater_field->find("limit=15, sort=random");

    but that's just randomly pulling 15 items from the first page, the one with id 1049.

    How do I go about randomising both the pages and the repeater items as well?

  4. I have a repeater field that contains title, an image field and two text fields, one for teaser and one for body. I can add data to all the fields except the teaser OK and save the page. As soon as I try adding text to the teaser field, I get a 403 error. The teaser field was using CKEditor, but I've now changed it to just a plain textarea but still get the same error.

    Anyone know what might be causing that?

  5. I'm getting the same error with PW 3.0.62. I installed it, updated my parent template with the format I wanted to use and then went to create a child page.

    I got the error, uninstalled the module as suggested by Macrura and refreshed the page I was trying to create and got redirected to page/edit/?id=XXXX&new=1 and it had created the name/title in the format I'd specified.

    Now I can create more child pages which automatically skip the add new page and have the expected name/title format, even though the module is no longer installed.

  6. I have three events all in October and I want my events page to list events under the month of their date field. But with the below code I get two under September and one under October.

    The date field values for the three events is:

    • 2018-10-13 00:00:00
    • 2018-10-20 00:00:00
    • 2018-10-27 00:00:00

    What am I doing wrong?

    function childrenInMonth($page, $month, $field = 'event_date') {
      $startTime = $month;
      $endTime = strtotime("next month", $startTime);
      return $page->children("$field>=$startTime, $field<$endTime, sort=$field");
    }
    
    $events = '';
    
    $start = $month = strtotime('today');
    $end = strtotime('+1 year');
    
    while($month < $end) :
    
      $event_pages = childrenInMonth($page, $month);
    
      if(count($event_pages)>0) :
    
        $events .='<h2>'. date('F', $month).'</h2>
        <ul>';
    
        foreach ($event_pages as $event) :
    
          $events .= '
            <li>
                <h3>'.$event->title.'</h3>
            </li>
          ';
    
        endforeach;
    
        $events .= '</ul>';
    
      endif;
    
      $month = strtotime("+1 month", $month);
    
    endwhile;

     

  7. I'm getting the following error on a production site:

    Quote

    Error: Cannot declare class ComposerAutoloaderInit4aa8a0e5775c7445960a959e7c2ad326, because the name is already in use (line 5 of /httpdocs/site/assets/cache/FileCompiler/vendor/composer/autoload_real.php)

    I don't get the error on my local version of the site.

    • Why does it happen in production and not local?
    • I guess it would be solved by PW not adding anything from the vendor folder to cache/FileCompiler, so how do I stop that?
    • Or is there something else I should be doing to fix it?
  8. How would you go about adding markup to an action outside a form field? For instance for an action I'm working on which sends emails, I'd like to be able to provide a button to preview the email in a modal window.

    Would it be with addHookAfter and if so, would I be targetting the action's class::method or the module's?

  9. I'm customising one of the actions that comes with the Admin Actions module and would like it to display a repeater matrix field.

    I've created a field in PW then gone to Export and copied the output and then pasted it into my action converting it from JSON to PHP format, so this is what I have:

    array(
        'name' => 'emailBody',
        'label' => 'Email body',
        'description' => '',
        'type' => 'repeaterMatrix',
        'matrix1_name' => 'page',
        'matrix1_label' => 'Choose existing page',
        'matrix1_head' => '{matrix_label} [• {matrix_summary}]',
        'matrix1_sort' => 1,
        'matrix2_name' => 'text',
        'matrix2_label' => 'Text',
        'matrix2_head' => '{matrix_label} [• {matrix_summary}]',
        'matrix2_sort' => 2,
        'matrix1_fields' => array(2),
        'matrix2_fields' => array(76),
        'repeaterFields' => '',
        'repeaterLoading' => 1,
        'rememberOpen' => null,
        'repeaterMinItems' => 1,
        'matrixN_head' => '{matrix_label} [• {matrix_summary}]',
        'columnWidth' => 100
    )

    When I load the action page I get:

    Quote

    if(empty($fieldIDs)) $fieldIDs = $this->field->get('repeaterFields');

    from FieldtypeRepeater/InputfieldRepeater.module at line 216

    I haven't done anything with PW admin pages or modules before so I'm not really sure what I'm doing or whether this is the right approach.

    I'm posting in a separate thread rather than the official support thread as what I'm having trouble with has more to do with my understanding of how the PW API works in admin pages than with the actual module itself.

    cc @adrian

  10. I actually want a Repeater Matrix field, not PageTable. I'm trying to implement this now and have created a field in PW then gone to Export and copied the output and then pasted it into my action converting it from JSON to PHP format. Is that the right way to go about it? Or can I point the field in the action to an already existing field? Will I be able to use any fieldtype in an action?

  11. All good now, thanks. ?

    I've got quite a bit more I want to do with this action like be able to use a PageTable field to be able to compose emails from a mix of existing pages and typed content, preview the email before sending, attach files uploaded to pages, and log email sends, but I think I'm probably better creating a new thread for that as it won't really be specific to your module, but more my limited coding abilities and inexperience working with the API.

  12. If you pasted the code I posted above into an action to test, it's probably because I removed all the bits I didn't change to make it shorter and easier to read. I added comments where I'd taken stuff out. So testAddress, email, body, etc. all exist in my version of the action.

    I had missed one $options['fromEmail'] which I've now changed to $options['from'] but other than I'm not getting any other errors.

    I've attached the action file if it helps.

    EmailBatcherCoordinator.action.php

×
×
  • Create New...