[Headless] Accessible API

  • drewm

    Approved the thread.
  • For things that do not currently have API classes, you can use the normal runtime functions (and the skip-template option) to fetch the data.


    Sets take arrays from any source. The docs includes a hardcoded array example to demonstrate this:

    PHP
    1. $Set->add_items([
    2. [
    3. 'id' => 1,
    4. 'title' => 'Hello',
    5. ],
    6. [
    7. 'id' => 2,
    8. 'title' => 'World',
    9. ],
    10. ]);



    Knowing this, you'd fetch categories like so:

    PHP
    1. $Set->add_items(perch_categories([
    2. 'skip-template' => true,
    3. ]));



    The API endpoints are not pages. So for page functions you need to tell Perch what page to use:


    PHP
    1. PerchSystem::set_page('/contact');
    2. $navigation_pages = perch_pages_navigation(['skip-template' => true]);
    3. $page_attrs = perch_page_attributes(['skip-template' => true]);
    4. $Nav_Set->add_items($navigation_pages);
    5. $PageAttrs_Set->add_items($page_attrs);