.tpl file and curly brackets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

.tpl file and curly brackets

Post 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?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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!!!
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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)
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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
Adrianc333
Forum Newbie
Posts: 14
Joined: Sat Feb 17, 2007 5:44 am
Location: South Yorkshire, UK

Post 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. :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It is more than likely smarty/template lite. phpBB uses no dollar signs in their template class.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

Please correct me! I don't see practical use of this feature nor is clever.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

ngungo wrote:Please correct me! I don't see practical use of this feature nor is clever.
Uh... huh? :? Image
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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".
Post Reply