Joomla VS Wordpress – Round 1
Posted by designzillas on 5/14/10
When using Drupal input formats with HTML Filtered enabled, the text gets passed through a variaty of functions which sanazite the user input. The HTML Filter removes harmfull content such as iframes, javascript and inline CSS. Drupal by default, stores the raw value in the database so that developers have fine control on how they want to output that variable. This blog article talks about the difference between the value, safe, and view variables and best practices in saving and outputting safe node values.
Let's jump right in to it! If you look at a full node within your template you will notice that all of the text fields have three variables attached to them:
The differenced between the three is very simple, but critical when deciding which one to use when saving your Drupal field values.
One thing we have to keep in mind is that the safe variables are only generated upon the "view" operation for the hook_nodeapi(). This means that node_invoke_nodeapi($node, 'view', $teaser, $page); needs to be called after you load the node. In other words, if you need the safe variables after calling node_load() you need to call node_build_content() which will remove the teaser delimeter and also call node_invoke_nodeapi() for the view operation.
Here is an example:
$node = node_load(12);
$node = node_build_content($node);
echo $node->field_my_field_name[0]["safe"];