The snippet( ) function

Each PHP script in a Grawlix theme is actually part of a given web page. The Grawlix CMS assembles HTML from different parts we call “snippets”. Writing this code:

<?=snippet('header')?>

Will grab the contents of a file called snippet.header.php and add it to the overall file. For example, the file called page.comic.php includes a header, a footer, and other snippets.

Technically you could name a snippet anything you want, like snippet.wokkawokka.php, as long as it begins with “snippet” and ends with “php”.

Here are some real snippets that the Grawlix CMS uses:

  • header
  • comic-nav
  • share
  • follow
  • twitterstream
  • transcript
  • comments
  • footer
  • sidebar
  • googleanalytics

These files must use the .php extension, but they don’t have to contain any PHP. Also, you can create your own snippets.

Wrap up

snippet('name') is a function for including a template file from your install’s filesystem. The text in quotes matches part of a filename. For example, snippet('header') corresponds to snippet.header.php. Likewise snippet('wokkawokka') would grab the “wokkawokka” snippet. That’s just an example, though. It’s not real.


Didn’t answer your question? Search this site or tell us what you’re looking for.