PerchFactory paging and layout includes

  • Hello,


    I'm extending the PerchFactory class in an app and ran into a few things. My classes don't specify an index table so ultimately I'm using get_filtered_listing(), not get_filtered_listing_from_index().


    Some of the below may be intentional and designed that way. And of course there's always the possibility I've implemented something incorrectly. None of the below is preventing me from achieving what I need, so just reporting in case any of this behaviour is not intentional.

    Layout includes


    I sometimes use Layout includes inside templates:


    HTML
    1. <perch:layout path="my_layout">


    This generally works. However, it doesn't when using the skip-template option. I resorted to using a template handler instead.



    Paging automatically enabled (when using count)

    When using the count option, paging seems to be automatically enabled regardless of the value of the paginate option.


    This is fine if I I'm only fetching one set of data on the page. However, if I'm fetching 2 or more sets of data and I only need one of them to be paginated, while the other(s) still needs to be limited by the count option, both sets will be paginated.


    I'll use demo_collection() below for demonstration:



    Using the start option is the only way I've found to actually disable the pagination:


    PHP
    1. demo_collection('Unicorns', [
    2. 'count' => 3,
    3. 'start' => 1,
    4. ]);


    ?page= always works


    Before I tried the start option I attempted to assign a different query string parameter name using the pagination-var option. The custom name I assign works, but ?page= also works regardless.



    PHP
    1. // default ?page=
    2. demo_collection('Elephants', [
    3. 'count' => 9,
    4. ]);
    5. // custom ?p=, default ?page= still applies here regardless
    6. demo_collection('Unicorns', [
    7. 'count' => 3,
    8. 'pagination-var' => 'p'
    9. ]);


    The custom name is used as expected in the pagination URLs in the template, but if I visit ?page=12, I'd get the 12th page for both Elephants and Unicorns; not just Elephants. So I'd have to refrain from using ?page= altogether to avoid unintentionally paginating something else on the page.

  • This generally works. However, it doesn't when using the skip-template option. I resorted to using a template handler instead.

    Could you clarify? If you're using skip-template then nothing in the template is used, including calls to layouts. So I'm clearly missing something!



    The custom name is used as expected in the pagination URLs in the template, but if I visit ?page=12, I'd get the 12th page for both Elephants and Unicorns; not just Elephants. So I'd have to refrain from using ?page= altogether to avoid unintentionally paginating something else on the page.

    Setting pagination-var should be enough! What do you have set for the paging key in your config/runway.php file?

  • Could you clarify? If you're using skip-template then nothing in the template is used, including calls to layouts. So I'm clearly missing something!


    True, but I'm also using the return-html option. I'd want the layout included in the returned HTML.


    Setting pagination-var should be enough! What do you have set for the paging key in your config/runway.php file?


    I haven't set one.

  • True, but I'm also using the return-html option. I'd want the layout included in the returned HTML.

    The HTML returned by return-html is processed in the same way with or without skip-template. The difference may come if your demo_collection() runtime function is not calling PerchTemplate::apply_runtime_post_processing() when skip-template is used.


    Quite a lot of the default functions will use skip-template as a queue not to call apply_runtime_post_processing() but then flip the switch back on if return-html is called.