<?php

/**
 * Return the path to a view file.
 */
function template($name)
{
	return SRC . "/../templates/$name.php";
}

/**
 * Render a view with the given data. Looks for `$view` through `template()`.
 */
function render($pathToBaseView, $data = [])
{
	ob_start();
	extract($data);
	require template($pathToBaseView);
	return ob_get_clean();
}

/**
 * Set/retrieve the current page layout in/from GLOBALS.
 */
function page_layout($layout = '')
{
	if ($layout !== '') $GLOBALS['page-layout'] = $layout;
	return $GLOBALS['page-layout'] ?? 'basic';
}

/**
 * Shorthand to render a page with the current layout.
 */
function page($view, $data = [])
{
	return render("layouts/" . page_layout(), ['view' => "pages/$view"] + $data);
}
