php basics
Nl2br line break syntax of Smarty template engine
The Smarty template engine also needs to use the automatic line wrapping function when outputting data, so Smarty also prepares the nl2br function to convert the "\n" line feed symbol into the HTML line feed symbol such as <br>,</ br> or <br\>, the effect is the same as the PHP nl2br function, the only difference is that Smarty's nl2br is used in the template file.
Smarty nl2br example: PHP file
<?php
$tpl>assign( 'TestString' ,'Welcome to Wibibi.\nHave a good day.' );
?>
This file is the basic writing method for assigning variable values to Smarty. First prepare this PHP file, set a variable TestString, and give a string value. Later, there will be a "\n" newline symbol on the sample file. Paragraph strings are converted into automatic line wrapping through the built-in nl2br function of Smarty.$tpl>assign( 'TestString' ,'Welcome to Wibibi.\nHave a good day.' );
?>
Smarty nl2br example: tpl template file
{TestString | nl2br }
Example outputTestString' ,'Welcome to Wibibi.
Have a good day.
Output result source codeHave a good day.
TestString' ,'Welcome to Wibibi.<br \>Have a good day.
In the Smarty template file, you only need to wrap the output string TestString with curly brackets, and use a vertical line "|" after the string followed by nl2br, so that the output result will have the effect of automatic line wrapping, because the original The "\n" in the string has been converted to HTML newline tag "<br \>" Hello!
Post a Comment
0 Comments