PHP Usage Notes

  1. Your code should echo or print the value you want to appear as the replacement for the tag.
  2. It is not necessary to begin or close your statement with open/close PHP tags. Though you may use them when/if necessary. Also an opening <?php tag is desirable to enable syntax highlighting.
  3. Your code is executed the same way as a ProcessWire template file and all API variables are locally scoped. Meaning, you can call upon $page, $pages, or any other API variables. directly. See also the PHP Properties section to the right.
  4. If attributes are specified in the tag (or in the Attributes field on this page), they will appear as locally scoped variables to your PHP code. For instance, in the tag [[hello_world first_name=Karena]], your code will have a $first_name variable populated with 'Karena'.
  5. If using attributes, it is optional though recommended that you define defaults in the Attributes field on this screen (even if blank is the default value).
  6. All attributes are also populated to an $attr array of [key=value]. For example: $attr['first_name'] == 'Karena', in case you find this syntax preferable, or necessary.
  7. If you use an attribute name that is the same as an API variable name (example: $page) then the API variable overrides the attribute name. In that case, the attribute value will only be accessible through $attr (example: $attr['page']).
  8. Your code receives an object named $hanna. This can be used for getting additional properties, or modifying the larger text value if necessary. See details in the PHP Properties section.
  9. The $page API variable available to your Hanna code represents the page where the Hanna code exists. It is possible for this to be different from wire('page'), which represents the page that originated the request.
  10. These code snippets are written to /site/assets/cache/HannaCode/[tag-name].php and directly executed rather than eval'd.

PHP Properties

$attrAn array of [key=value] attributes passed to your Hanna code.
$pageThe page where the Hanna code exists.
$hanna->nameThe name (string) of the current Hanna code.
$hanna->fieldThe Field object representing the text.
$hanna->valueThe larger text where the Hanna code lives. This property may also be set.

Please note that "name" is a reserved word and may not be used as an attribute name.

Javascript Usage Notes

  1. It is not necessary to include <script> tags in your code unless you want to. They will be automatically inserted when not already present.
  2. If attributes are specified in the tag (or in the attributes section of this page), they will appear as locally scoped variables to your Javascript code. For instance, in the tag [[hello_world first_name=Karena]], your code will have a first_name variable populated with 'Karena'.
  3. All attributes are also populated to an attr object of attr.key=value (i.e. attr.first_name == 'Karena'), in case you find this syntax preferable.
  4. If using attributes, it is recommended that you define defaults in the Attributes field on this screen (even if blank is the default value).
  5. Note that name is a reserved word and may not be used as an attribute name.