IMPORTANT: This solution is applicable to SilverStripe 2.X. If you're using SilverStripe 3.0 - see SS3.0 answer on this page.
You'd simply add a getter to your model:
public function FormattedAddress {
return nl2br($this->OfficeAddr);
}
Then call it in your template:
<p>$FormattedAddress</p>
OR - if you want to adhere to MVC, the more complex solution is...
Assuming you've used the HTMLText field type you could extend the HTMLText class:
Create a file called - Extended_HTMLText.php (or something similar) - add the following to it and save it into your code directory:
class Extended_HTMLText extends HTMLText {
function NL2BR() {
return nl2br($this->value);
}
}
Add the following to your _config.php file:
Object::useCustomClass('HTMLText', 'Extended_HTMLText', true);
Then you can call it in you template like so:
<p>$OfficeAddr.NL2BR</p>
This at least takes your view logic out of your model ;)