Snippet and chunk basics
Snippets are executable PHP code objects that provides some functionality when called.
In the previous example, NewsEditor
is a snippet. The only content of the Post a Blog! page was the call to the NewsEditor
snippet; the snippet takes care of displaying a form and storing the values entered through it as a new document. There is a whole chapter on Snippets in this book (Chapter 8, Snippets). In this section, you will learn the bare minimum about snippets that is necessary to follow along in the ensuing chapters.
Generating output
Most snippets return an output that gets shown in the template at the same location from which the call to the snippet was made.
Such output can be returned by snippets in two ways:
Return the HTML: In this method, there is less control over what the snippet returns. Changes in the returned output can only be made by editing the snippet code, as the snippet has the HTML that has to be returned within the snippet code.
Use chunks: Snippets can...