I am developing a SilverStripe project. In my project, I am trying to make an Ajax request to the controller and render the partial view. I am following this tutorial, https://www.silverstripe.org/learn/lessons/v4/ajax-behaviour-and-viewabledata-1. But it is not working. Please, see my code below.
This is my index function in the controller
public function index(HTTPRequest $request)
{
if ($request->isAjax()) {
return $this->renderWith('Authors');
}
return [
'Blogs' => $this->getBlogs(),
];
}
As you can see in the code, I am trying to render the Authors partial view in the Includes folder.
I created the partial view in the Includes folder in the templates folder with the following code.
<h1>This is the previous events partial view.</h1>
This is how I make ajax call in Jquery
$.get(url)
.then(function (response) {
//render the view here
})
.catch(function (error) {
console.log(error);
})
But the ajax call is throwing an error. This is the error.
[User Warning] None of the following templates could be found: cyber-duck/templates/PreviousEvents in themes "Array ( [0] => my-themes [1] => $default ) "
GET /upcoming-events?page=2
Line 210 in /var/www/public/vendor/silverstripe/framework/src/View/SSViewer.php
Source
201 $message .= print_r($templates, true);
202
203 $themes = self::get_themes();
204 if (!$themes) {
205 $message .= ' (no theme in use)';
206 } else {
207 $message .= ' in themes "' . print_r($themes, true) . '"';
208 }
209
210 user_error($message, E_USER_WARNING);
211 }
212 }
213
214 /**
215 * Triggered early in the request when someone requests a flush.
216 */
What is the issue and how can I fix it?