Page 1 of 2

.tpl file and curly brackets

Posted: Tue Apr 03, 2007 11:26 am
by ngungo
This a two-part question that I am not sure if they are related.
1. Is .tpl file extension is a part of php syntax parsing like .php
2. What are other uses of curly brackets besides statement grouping?

Posted: Tue Apr 03, 2007 11:29 am
by Oren

Posted: Tue Apr 03, 2007 11:45 am
by ngungo
Man! You are quick. Thanks.
Oren wrote:

Code: Select all

$file=file_get_contents("http://www.go{$my_var}ogle.com/search?&q=n93+amazon.com&btnI"); 
Put {$my_var} wherever you wish within the URL.
So, in general, the curly brackets force the variable within them evaluated (in a string)? How about return of a function?
I could not find any reference to it. Help!!!

Posted: Tue Apr 03, 2007 2:01 pm
by Oren
ngungo wrote:So, in general, the curly brackets force the variable within them evaluated (in a string)?
Well... no, not exactly.

For instance, this is valid:

Code: Select all

$my_str = 'some other text.';
echo "some text, $my_str"; // prints: some text, some other text.
Now consider the following example:

Code: Select all

$my_str = 'some other text.';
$my_str2 = 'another string';

echo "some text, $my_str2"; // prints: some text, another string
In this example, you can see that PHP uses the text in $my_str2, but what if you wanted PHP to use the text in $my_str followed by the string '2' (= you wanted it to print: some text, some other text.2 instead of some text, another string)?

For that you will have to do:

Code: Select all

$my_str = 'some other text.';
$my_str2 = 'another string';

echo "some text, {$my_str}2"; // prints: some text, some other text.2
P.S You can choose to do {$my_str} or ${my_str} - the result is exactly the same.

Edit: For more information about this see: Variable parsing (read the whole page if you need to)

Posted: Tue Apr 03, 2007 2:16 pm
by Begby
If you have a .tpl file and its got a bunch of {$var} stuff in it, then its probably a smarty template.

http://smarty.php.net

Posted: Tue Apr 03, 2007 2:17 pm
by Oren
Begby wrote:If you have a .tpl file and its got a bunch of {$var} stuff in it, then its probably a smarty template.

http://smarty.php.net
Or phpBB, or... who knows :P

Posted: Tue Apr 03, 2007 2:37 pm
by Adrianc333
The .tpl is just like a HTML file really.

The {} braces can be anything, it just usually goes like this,

str_replace("{" . $original . "}", $replace, $file):

Something like that. :)

Posted: Tue Apr 03, 2007 3:22 pm
by RobertGonzalez
It is more than likely smarty/template lite. phpBB uses no dollar signs in their template class.

Posted: Tue Apr 03, 2007 3:27 pm
by Oren
Everah wrote:It is more than likely smarty/template lite. phpBB uses no dollar signs in their template class.
He never showed us his file so it might be with $ or without it. Anyway, it doesn't really matter if it is Smarty, phpBB or whatever.

Posted: Tue Apr 03, 2007 3:31 pm
by RobertGonzalez
You are totally right. I used the example he posted from one of your other posts and assumed it was a smarty var. My fault.

Good catch by the way Oren.

Posted: Tue Apr 03, 2007 4:32 pm
by Oren
Everah wrote:You are totally right. I used the example he posted from one of your other posts and assumed it was a smarty var.
lol, yeah... that happens to me too sometimes :P

Posted: Wed Apr 11, 2007 2:09 pm
by ngungo
Please correct me! I don't see practical use of this feature nor is clever.

Posted: Wed Apr 11, 2007 3:58 pm
by RobertGonzalez
ngungo wrote:Please correct me! I don't see practical use of this feature nor is clever.
Uh... huh? :? Image

Posted: Wed Apr 11, 2007 5:52 pm
by Burrito
ngungo wrote:Please correct me! I don't see practical use of this feature nor is clever.
it is very useful. you can create 15 different looking sites that all run on the same 'engine'. by using the {} you can have php inject variable values into the template so that when a user visits the site, they will see something dynamically loaded on the page regardless of which 'look and feel' they're accessing.

Posted: Wed Apr 11, 2007 6:24 pm
by ngungo
I have looked into smarty and phpBB template system "a little bit". They do not impress me at all for the fact that they are too verbose or other words "lack of brevity".