function slice_content($slice, $linkResolver) { global $WPGLOBAL; $sliceFile = views_dir() . '/slices/' . $slice->getSliceType(); $sliceLabelFile = $sliceFile . '-' . $slice->getLabel() . '.php'; $sliceFile = $sliceFile . '.php'; if (file_exists($sliceLabelFile)) { include $sliceLabelFile; } elseif (file_exists($sliceFile)) { include $sliceFile; } else { echo $slice->asHtml($linkResolver); } }
function not_found($app, $skin = null) { global $WPGLOBAL; $prismic = $WPGLOBAL['prismic']; $notfound = $prismic->get_404(); $app->response->setStatus(404); $ctx = array('notfound' => $notfound); if ($skin) { $ctx['skin'] = $skin; } $file_path = views_dir() . '/404.php'; if (file_exists($file_path)) { // Avoid an infinite loop render($app, '404', $ctx); } else { echo '<h1>404 Not found</h1>'; echo 'Additionnaly the 404 template seems to be missing from the skin.'; } }
// To have nicer looking URLs, it is recommended to add a specific route for each mask you create. $app->get('/document/:id/:slug', function ($id, $slug) use($app, $prismic) { $doc = $prismic->get_document($id); if (!$doc) { not_found($app); return; } $permalink = $prismic->linkResolver->resolveDocument($doc); if ($app->request()->getPath() != $permalink) { // The user came from a URL with an older slug $app->response->redirect($permalink); return; } $skin = $prismic->get_skin(); // Do we have a template for this type? $file_path = views_dir() . '/' . $doc->getType() . '.php'; $template = file_exists($file_path) ? $doc->getType() : 'document'; render($app, $template, array('single_post' => $doc, 'skin' => $skin)); }); // Page // Since pages can have parent pages, the URL can contains several portions $app->get('/:path+', function ($path) use($app, $prismic) { $page_uid = check_page_path($path, $prismic, $app); $skin = $prismic->get_skin(); if ($page_uid) { $page = $prismic->by_uid('page', $page_uid); if (!$page) { not_found($app, $skin); return; } render($app, 'page', array('single_post' => $page, 'skin' => $skin));
public function render($PageName) { require_once views_dir() . "{$PageName}.php"; }