Replies: 2 comments 3 replies
-
When using the standard You should instead use our View class. use Statamic\View\View;
return View::make('pages/home', $data)->layout('layout'); If you don't want to use a controller, you could consider a view model. https://statamic.dev/view-models In your view_model: 'App\ViewModels\HomeViewModel' and then create the view model php file in <?php
namespace App\ViewModels;
use Statamic\View\ViewModel;
class HomeViewModel extends ViewModel
{
public function data(): array
{
return $this->makeApiCall();
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Where would that ArticleStats php file live? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I could not quite figure out how to use controllers & the advantages of .antlers-files. How can I pass the data from my collections and data i fetched from an external api-call within the controller both at once to a antlers-view.
So far I tried:
public function home() {
$data = external Api-Call
$entry = \Statamic\Facades\Entry::find("home");
return view('pages/home', $entry ,$data);
}
But now my view does not include my specified-layout and all in all it seems quite messy. Is there a better way of not having to use individual routing but passing the fetched data from the controller to my antlers-view.
Beta Was this translation helpful? Give feedback.
All reactions