3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Repos\PageRepo;
6 use BookStack\Exceptions\NotFoundException;
7 use Illuminate\Http\Request;
9 class PageTemplateController extends Controller
14 * PageTemplateController constructor.
17 public function __construct(PageRepo $pageRepo)
19 $this->pageRepo = $pageRepo;
20 parent::__construct();
24 * Fetch a list of templates from the system.
25 * @param Request $request
26 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
28 public function list(Request $request)
30 $page = $request->get('page', 1);
31 $search = $request->get('search', '');
32 $templates = $this->pageRepo->getPageTemplates(10, $page, $search);
35 $templates->appends(['search' => $search]);
38 return view('pages.template-manager-list', [
39 'templates' => $templates
44 * Get the content of a template.
46 * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
47 * @throws NotFoundException
49 public function get($templateId)
51 $page = $this->pageRepo->getById('page', $templateId);
53 if (!$page->template) {
54 throw new NotFoundException();
57 return response()->json([
58 'html' => $page->html,
59 'markdown' => $page->markdown,