PHPFront logo
PHPFront Online Documentation now available! PHPFront is available on Composer: composer require ox-harris/phpfront Contact us to place an ad here...

Including Template Parts

Include files at specified places in the main template

As a true template engine, PHPFront is made to help you dynamically and easily compose a template. You could separate parts of your template into different files (the header.html, footer.html, or the sidebar.html, for example) and use PHPFront::setInclude() function to build these up again – at runtime.

Function

    
      
      PHPFront::setInclude($element_selector, $include_path);
      
    
    

This function accepts two parameters:
$element_selector - the element selector,
$include_path – the path to the include file (absolute path or relative path).

Usage

      
        
		// This includes a file using a relative path
		$PHPFront->setInclude('#header_wrapper', '../../resources/header.html');

		// This includes a file using an absolute path
		$PHPFront->setInclude('#footer_wrapper', 'c://xamp/htdocs/app/resources/footer.html');

		// This includes the sidebar.html file for all pages except the login page
		if ($_POST['Controller'] == '/login')
		{
			// Do nothing
		}
		else
		{
			$PHPFront->setInclude('#sidebar_wrapper', '../../resources/sidebar.html');
		}

      
      

All includes must be set before calling on the PHPFront::render() function.

PHPFront throws ErrorException when an include path could not be found or the file contains invalid markup.

Summary

  • The PHPFront::setInclude() function includes files at specified places in the main template. Recall

Good progress made so far!

Back to Working with PHPFront

See Also