Latest blog posts inside Block

  • Hi!

    I have one question related to <perch:block>. I created a page with one Perch Region where the user can add various content blocks.

    Because I installed Perch Blog too, I got the idea to add a block containing the latest blog posts. But I realised I do not know, how to do that - as far as I can tell, it is more complicated than just adding a few fields inside a block. :) I would be really grateful if someone could point me in the right direction.

    Thank you!

  • drewm

    Approved the thread.
  • Keep in mind that if the region doesn't use that block, you'll still be doing the work of retrieving the posts and not using it.

    PerchSystem::set_var is a bit old hat, but works just fine. The better way to do it would be to use the data option with perch_content_custom()

    1. perch_content_custom('Region name', [
    2.     'data' => [
    3.         'posts' => perch_blog_recent_posts(5, true)
    4.     ],
    5. ]);
  • Thank you ryan, it works.

    I´m just a little bit confused. How is it possible that the variable "connects" to <perch:content> and imports its content there?

    We're basically passing data into the template for it to render, in the code example I sent it's the `PerchSystem::set_var` line doing that, and in Drew's better example, it's the 'data' option passed into the perch_custom_content. Really handy!