diff --git a/Smarty.class.php b/Smarty.class.php index d3a7c17a..0c37edbe 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -368,7 +368,7 @@ class Smarty if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $compiled_contents, $match)) { $strip_tags = $match[0]; $strip_tags_modified = preg_replace("!$ldq/?strip$rdq|[\t ]+$|^[\t ]+!m", '', $strip_tags); - $strip_tags_modified = preg_replace('![\r\n]+!m', ' ', $strip_tags_modified); + $strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified); for ($i = 0; $i < count($strip_tags); $i++) $compiled_contents = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $strip_tags_modified[$i], $compiled_contents, 1); diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index 9eb8c468..0ed2e099 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -22,3 +22,16 @@ My interests are: ({$FirstName|@count}) {insert name=paginate} + +testing strip tags +{strip} + + + + +
+ + This is a test + +
+{/strip} diff --git a/doc.sgm b/doc.sgm index f81f359a..c579567a 100644 --- a/doc.sgm +++ b/doc.sgm @@ -170,7 +170,7 @@ chown nobody:nobody templates_c Setting up Smarty There are several variables that are at the top of the Smarty.class.php file. You - can usually get away with leaving these at thier default settings. This is a list + can usually get away with leaving these at their default settings. This is a list of them and what each one does. @@ -430,7 +430,7 @@ $output = $smarty->fetch("./templates/index.tpl"); Variables - There are three basic types of variables in Smarty, each with thier + There are three basic types of variables in Smarty, each with their own unique syntax. @@ -530,7 +530,9 @@ Your last login was on {$lastLoginDate} Attributes Attributes to functions are much like HTML attributes. Static - values must be enclosed in parenthesis. Variable values may + values don't have to be enclosed in quotes, but is recommended. + If not quoted, you may use a syntax that Smarty may confuse + with another function, such as a boolean value. Variables may also be used, and should not be in parenthesis. @@ -594,10 +596,10 @@ bodyBgColor = #000000 tableBgColor = #000000 rowBgColor = #00ff00 -[ Customer ] +[Customer] pageTitle = "Customer Info" -[ Login ] +[Login] pageTitle = "Login" focus = "username" Intro = """This is a value that spans more @@ -739,7 +741,7 @@ Intro = """This is a value that spans more Let's say you have a page with a banner slot at the top. The template - has a banner_id value, and needs to call a function to get the banner. + has banner_id and page_id values, and needs to call a function to get the banner. Template example of function insert @@ -774,15 +776,116 @@ Intro = """This is a value that spans more if,elseif,else - + + if statements in Smarty have much the same flexability as php if statements, + with a few added features for the template engine. + Every if must be paired with /if. else and elseif are also permitted. + "eq", "ne","neq", "gt", "lt", "lte", "le", "gte" "ge","is","is not","not", + "mod","by","==","!=",">","<","<=",">=" are all valid conditional qualifiers. + + +Template example of if statements + + +{if $name eq "Fred"} + Welcome Sir. +{elseif $name eq "Wilma"} + Welcome Ma'am. +{else} + Welcome, whatever you are. +{/if} + +{* an example with "or" logic *} +{if $name eq "Fred" or $name eq "Wilma"} + ... +{/if} + +{* parenthesis are allowed *} +{if ( $amount lt 0 or $amount gt 1000 ) and $volume ne #minVolAmt#} + ... +{/if} + +{* you can also imbed php functionality, where appropriate *} +{if count($var) lt 0} + ... +{/if} + +{* test if values are even or odd *} +{if $var is even} + ... +{/if} +{if $var is odd} + ... +{/if} +{if $var is not odd} + ... +{/if} + +{* test if var is divisable by 4 *} +{if $var is mod 4} + ... +{/if} + +{* test if var is even, grouped by two. i.e., +1=even, 2=even, 3=odd, 4=odd, 5=even, 6=even, etc. *} +{if $var is even by 2} + ... +{/if} + + + ldelim,rdelim - + + ldelim and rdelim are used for displaying the literal delimiter, in + our case "{" or "}". The template engine always tries to interpret + delimiters, so this is the way around that. + + +Template example of ldelim, rdelim + + +{* this will print literal delimiters out of the template *} + +{ldelim}funcname{rdelim} is how functions look in Smarty! + + + literal - + + Literal tags allow a block of data to be taken literally, + not being interpreted by the Smarty engine. This is handy + for things like javascript sections, where there maybe + curly braces and such things that would confuse the template + parser. Anything within {literal}{/literal} tags is not + interpreted, but displayed as-is. + + +Template example of literal tags + + +{literal} + <script language=javascript> + + <!-- + function isblank(field) { + if (field.value == '') + { return false; } + else + { + document.loginform.submit(); + return true; + } + } + // --> + + </script> +{/literal} + + section,sectionelse @@ -790,8 +893,39 @@ Intro = """This is a value that spans more strip - + + strip is another nice feature of the template engine. Many times + you run into the issue where white space and carriage returns + affect the output of the rendered HTML (browser "features"), so you + must run all your tags together in the template to get the + desired results. This usually ends up in unreadable or + unmanagable templates. + + + Anything within {strip}{/strip} tags in Smarty are stripped of + the extra spaces or carriage returns before they are displayed. + This way you can keep your templates readable, and not worry + about extra white space causing problems. + + +Template example of strip tags + + +{strip} + + + + +
+ + This is a test + +
+{/strip} + +
+
Custom Functions diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index d3a7c17a..0c37edbe 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -368,7 +368,7 @@ class Smarty if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $compiled_contents, $match)) { $strip_tags = $match[0]; $strip_tags_modified = preg_replace("!$ldq/?strip$rdq|[\t ]+$|^[\t ]+!m", '', $strip_tags); - $strip_tags_modified = preg_replace('![\r\n]+!m', ' ', $strip_tags_modified); + $strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified); for ($i = 0; $i < count($strip_tags); $i++) $compiled_contents = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $strip_tags_modified[$i], $compiled_contents, 1); diff --git a/templates/index.tpl b/templates/index.tpl index 9eb8c468..0ed2e099 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -22,3 +22,16 @@ My interests are: ({$FirstName|@count}) {insert name=paginate} + +testing strip tags +{strip} + + + + +
+ + This is a test + +
+{/strip}