Level 9
view("cms.articles.{$slug}")->renderSections()['content'])
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am building a tiny custom CMS for a project. I want show an excerpt from each article on the index page.
Each of my article blades has @section('content') ... @endsection with the article contents.
Is it possible to extract the contents from this blade section in the controller?
Here is my controller:
public function index()
{
$articles = File::files(resource_path('views/cms/articles'));
foreach ($articles as $article)
{
$slug = explode('.', $articles->getFilename())[0];
// Is it possible to get contents into a string here?
dd(view("cms.articles.{$slug}"));
}
return view('articles-index', compact('articles'));
}
view("cms.articles.{$slug}")->renderSections()['content'])
Please or to participate in this conversation.