Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Silverstripe 3 this would be best achieved by creating a <a href="http://doc.silverstripe.com/framework/en/reference/dataextension"><code>DataExtension</code> class</a> (as opposed to overriding the class). (Note: this would be possible in 2.4.x as well, but the code would be quite different.)</p> <p>Create a new class called <code>TextFormatter</code> which extends <code>Extension</code>:</p> <pre><code>class TextFormatter extends Extension { public function NL2BR() { return nl2br($this-&gt;owner-&gt;value); } } </code></pre> <p>Specify in config that the <code>Text</code> class should be extended with your brand new class. This can be done either in your <code>_config.php</code> file or (preferably) in a YAML file.</p> <p>If you don't already have one, create a new file at <code>mysite/_config/extensions.yml</code> with the following content (or you can append this to your existing file):</p> <pre><code>Text: extensions: ['TextFormatter'] </code></pre> <p>This just says "extend the class <code>Text</code> with the class <code>TextFormatter</code>" which will make our new <code>NL2BR</code> function available on all <code>Text</code> objects.</p> <p>Now, in your templates you can simply call <code>$OfficeAddr.NL2BR</code> and the output will be run through your function before being output.</p> <p>Note that I've assumed your model uses <code>Text</code> as the field type rather than <code>HTMLText</code> as a previous answer has assumed. If you are using <code>HTMLText</code> you can simply extend that class instead by changing your <code>extensions.yml</code> file as appropriate.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload