fixed <?php tag at beginning of files, updated docs

This commit is contained in:
mohrt
2001-02-19 19:10:58 +00:00
parent 0f01cd9860
commit 94e1ecd90e
8 changed files with 29 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
<? <?php
require_once "PEAR.php"; require_once "PEAR.php";

7
FAQ
View File

@@ -88,3 +88,10 @@ Q: I get this error when passing variables to {include}:
/path/to/Smarty/templates_c/index.tpl.php on line 8 /path/to/Smarty/templates_c/index.tpl.php on line 8
A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing
variables to included templates, you will need PHP 4.0.4 or later. variables to included templates, you will need PHP 4.0.4 or later.
Q: I get PHP errors in my {if} tag logic.
A: All conditional qualifiers must be separated by spaces. This syntax will not
work: {if $name=="Wilma"} You must instead do this: {if $name == "Wilma"}.
The reason for this is syntax ambiguity. Both "==" and "eq" are equivalent
in the template parser, so something like {if $nameeq"Wilma"} wouldn't be
parsable by the tokenizer.

View File

@@ -505,8 +505,9 @@ class Smarty
'{literal}', $template_contents); '{literal}', $template_contents);
/* Gather all template tags. */ /* Gather all template tags. */
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match); preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}(\n)?!s", $template_contents, $match);
$template_tags = $match[1]; $template_tags = $match[1];
$template_newlines = $match[2];
/* Split content by template tags to obtain non-template content. */ /* Split content by template tags to obtain non-template content. */
$text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_contents); $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_contents);
@@ -515,12 +516,12 @@ class Smarty
/* loop through text blocks */ /* loop through text blocks */
for($curr_tb = 0; $curr_tb <= count($text_blocks); $curr_tb++) { for($curr_tb = 0; $curr_tb <= count($text_blocks); $curr_tb++) {
/* match anything within <? ?> */ /* match anything within <? ?> */
if(preg_match_all('!(<\?[^?]*?\?>|<script\s+language\s*=\s*[\"\']?php[\"\']?\s*>)!i',$text_blocks[$curr_tb],$sp_match)) { if(preg_match_all('!(<\?[^?]*?\?>|<script\s+language\s*=\s*[\"\']?php[\"\']?\s*>)(\n)?!i',$text_blocks[$curr_tb],$sp_match)) {
/* found at least one match, loop through each one */ /* found at least one match, loop through each one */
foreach($sp_match[0] as $curr_sp) { for($curr_sp = 0; $curr_sp <= count($sp_match[0]); $curr_sp++) {
if(!$this->allow_php) { if(!$this->allow_php) {
/* we don't allow php, so echo everything */ /* we don't allow php, so echo everything */
$text_blocks[$curr_tb] = str_replace($curr_sp,'<?php echo \''.str_replace("'","\'",$curr_sp).'\'; ?>',$text_blocks[$curr_tb]); $text_blocks[$curr_tb] = str_replace($sp_match[0][$curr_sp],'<?php echo \''.str_replace("'","\'",$sp_match[0][$curr_sp]).'\'; ?>',$text_blocks[$curr_tb]);
} }
elseif(!preg_match("!^(<\?(php | )|<script\s*language\s*=\s*[\"\']?php[\"\']?\s*>)!i",$curr_sp)) elseif(!preg_match("!^(<\?(php | )|<script\s*language\s*=\s*[\"\']?php[\"\']?\s*>)!i",$curr_sp))
/* we allow php, so echo only non-php tags */ /* we allow php, so echo only non-php tags */

View File

@@ -1,4 +1,4 @@
<? <?php
require("Smarty.class.php"); require("Smarty.class.php");

View File

@@ -1242,7 +1242,8 @@ Intro = """This is a value that spans more
"gt", "lt", "lte", "le", "gte" "ge","is even","is odd", "is not "gt", "lt", "lte", "le", "gte" "ge","is even","is odd", "is not
even","is not odd","not","mod","div by","even by","odd even","is not odd","not","mod","div by","even by","odd
by","==","!=",">", "<","<=",">=" are all valid conditional by","==","!=",">", "<","<=",">=" are all valid conditional
qualifiers. qualifiers, and must be separated from surrounding elements by
spaces.
</para> </para>
<example> <example>
<title>if statements</title> <title>if statements</title>
@@ -1266,6 +1267,12 @@ Intro = """This is a value that spans more
... ...
{/if} {/if}
{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}
{* parenthesis are allowed *} {* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#} {if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}

View File

@@ -1,4 +1,4 @@
<? <?php
require("Smarty.class.php"); require("Smarty.class.php");

View File

@@ -1,4 +1,4 @@
<? <?php
require_once "PEAR.php"; require_once "PEAR.php";

View File

@@ -505,8 +505,9 @@ class Smarty
'{literal}', $template_contents); '{literal}', $template_contents);
/* Gather all template tags. */ /* Gather all template tags. */
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_contents, $match); preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}(\n)?!s", $template_contents, $match);
$template_tags = $match[1]; $template_tags = $match[1];
$template_newlines = $match[2];
/* Split content by template tags to obtain non-template content. */ /* Split content by template tags to obtain non-template content. */
$text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_contents); $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_contents);
@@ -515,12 +516,12 @@ class Smarty
/* loop through text blocks */ /* loop through text blocks */
for($curr_tb = 0; $curr_tb <= count($text_blocks); $curr_tb++) { for($curr_tb = 0; $curr_tb <= count($text_blocks); $curr_tb++) {
/* match anything within <? ?> */ /* match anything within <? ?> */
if(preg_match_all('!(<\?[^?]*?\?>|<script\s+language\s*=\s*[\"\']?php[\"\']?\s*>)!i',$text_blocks[$curr_tb],$sp_match)) { if(preg_match_all('!(<\?[^?]*?\?>|<script\s+language\s*=\s*[\"\']?php[\"\']?\s*>)(\n)?!i',$text_blocks[$curr_tb],$sp_match)) {
/* found at least one match, loop through each one */ /* found at least one match, loop through each one */
foreach($sp_match[0] as $curr_sp) { for($curr_sp = 0; $curr_sp <= count($sp_match[0]); $curr_sp++) {
if(!$this->allow_php) { if(!$this->allow_php) {
/* we don't allow php, so echo everything */ /* we don't allow php, so echo everything */
$text_blocks[$curr_tb] = str_replace($curr_sp,'<?php echo \''.str_replace("'","\'",$curr_sp).'\'; ?>',$text_blocks[$curr_tb]); $text_blocks[$curr_tb] = str_replace($sp_match[0][$curr_sp],'<?php echo \''.str_replace("'","\'",$sp_match[0][$curr_sp]).'\'; ?>',$text_blocks[$curr_tb]);
} }
elseif(!preg_match("!^(<\?(php | )|<script\s*language\s*=\s*[\"\']?php[\"\']?\s*>)!i",$curr_sp)) elseif(!preg_match("!^(<\?(php | )|<script\s*language\s*=\s*[\"\']?php[\"\']?\s*>)!i",$curr_sp))
/* we allow php, so echo only non-php tags */ /* we allow php, so echo only non-php tags */