Output functions

Revision as of 18:02, 12 April 2006 by Eloy Lafuente (stronk7) (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page tries to explain a bit how dynamic data should be sent from Moodle to the browser in a organised and standard way. Obviously it's possible to have your own output methods but, thinking that you are going to share your code (yep, this is an OpenSource project!) and in the collaborative way we try to build and maintain the system every day, it would be really better to follow the basic guidelines explained below.

By using them you will be helping to have better, more secure and readable code. Spend some minutes trying to understand them, please!

Of course, this functions can be discused, modified and new functions can arrive if there are some good reasons for it. Just discuss it in the General developer forum at moodle.org.

For each of the functions below we'll try to explain when they should be used, commenting the most important parameters supported and their meaning. Let's go.

p() and s()

function s($var, $strip=false) and function p($var, $strip=false)

This functions share the same code so they will be explained together. The only difference is that s() returns the string while p() prints it directly.

This functions should be used to:

  • print all the values of form fields like <input> or <textarea> tags.
  • to show plain (non html) text that have been introduced by the user (search string, quiz responses...).
  • in general, all the dynamic data, not being html, that doesn't need to be cleaned nor processed by filters

The key parameter for this function is:

  • strip: it decides if we want to strip slashes from the string or no.



format_text()

This function should be used when:


format_string()

print_textarea()