Learning to create a snippet
In this section, we will learn to create a snippet by using a simple 'Hello World' program in PHP. To test the output, we will create a resource with the following details:
Field Name |
Field Value |
---|---|
Title |
Creating a Snippet |
Uses template |
Learning MODx default template |
Document content |
[!helloworld!] |
Show in menu |
Disable |
From the earlier chapter on using snippets, we have learned that a snippet can do one or more of the following three things:
Return HTML output that gets inserted in place of the snippet call
Create and store values in placeholders, which can later be used in the document or template that called the snippet
Create and store values in placeholders, process a chunk that uses these placeholders, and insert the chunk's HTML with the placeholders' values in the document or template that called the snippet
In this section, we will learn how to make regular PHP code do all of these things. For this demonstration, we will convert the following PHP code...