RAFT Ain't For Templating

RAFT is simple templating for PHP. It strives for simplicity because building a big templating system is too much overhead. It takes advantage of the fact that PHP, in itself, is already a good templating system.

Assigning Values to a Key

Key Value Code
string Assigned value to a string key.
raft("string", "Assigned value to a string key.");
2 Assigned value to a numeric key.
raft(2, "Assigned value to a numeric key.");
first.second.third Assigned value to a nested key.
raft("first.second.third", "Assigned value to a nested key.");
anonymous_function1 Used the output of an anonymous function.
raft("anonymous_function1", function() {
  echo "Used the output of an anonymous function.";
});
anonymous_function2 Used the return value of an anonymous function.
raft("anonymous_function2", function() {
  return "Used the return value of an anonymous function.";
});
multiple_assignment1 1st value of multiple assignment.
raft(array(
  "multiple_assignment1" => "1st value of multiple assignment.",
  "multiple_assignment2" => "2nd value of multiple assignment."
));
multiple_assignment2 2nd value of multiple assignment.
function1 Used a function's output.
function raft_function1() {
  echo "Used a function's output.";
}
function2 Used a function that returns a value.
function raft_function2() {
  return "Used a function that returns a value.";
}
output_buffering Captured value using output buffering.
raft("!BEGIN:output_buffering");
echo "Captured value using output buffering.";
raft("!END:output_buffering");
ob.nested.key Captured value using output buffering with nested key
raft("!BEGIN:ob.nested.key");
echo "Captured value using output buffering with nested key";
raft("!END:ob.nested.key");

Things to Keep in Mind

Format of keys is /^\w+(\.\w+)*$/

In layman terms, this means your keys must consist of words separated by a dot (.). Words can only contain alphanumeric characters.

# CORRECT
variableName
Person_Name
1
# INCORRECT
variable-name
Person Name
!@#$%

!BEGIN and !END must be used in pairs

Otherwise, untold havoc will ensue. You have been warned.

# CORRECT
raft("!BEGIN:sandwich");
echo "Bologna!";
raft("!END:sandwich");
# INCORRECT
raft("!BEGIN:sandwich");
echo "Bologna!";

# FIRE & BRIMSTONE!

Keys next to !BEGIN and !END must match

Ditto.

# CORRECT
raft("!BEGIN:sandwich");
echo "Bologna!";
raft("!END:sandwich");
# INCORRECT
raft("!BEGIN:sandwich");
echo "Bologna!";
raft("!END:pita");

# Bologna!
# Expected to capture sandwich, but received pita
Fork me on GitHub