Explain what this does

Associate
Joined
31 Jan 2007
Posts
1,860
Hey,
I'm currently working on a site for a family member and need a news system adding in. In the past I used to use CuteNews, It worked really well but now I want to attempt to make my own version. I have opened one of cutenews .tpl files and don;t understand the code in there.

If possible, could someone look at the file linked to (exact copy of the file from cutenews) and just explain what each bit does? It'd be highly appreciated.

The main bits I want to know about are:

1.) $template_active = <<<HTML

2.) <div>{short-story}</div>

3.) <div style="float: right;">[full-link]

4.) HTML;

5.) $template_comment = <<<HTML

I realise some parts like the bit in curly braces are replaced by other data but my question is HOW?

It would help me tremendously if someone could help me understand those bits highlighted above.

The file is at this link

Thanks

Neil
 
Last edited:
Hello Neil,

The curly brackets are usually PHP variables (I believe) which take the data from the database or another PHP file. Looking at your example a .tpl file is a smarty template and is used by many different software to make it easier to find which file to edit and separate the majority of the PHP to avoid confusion.

Jack
 
Ok, How do the curly brackets get changed into the proper data from the database?

and what do the bits in square brackets and the bits with several chevrons mean?
 
Ok, How do the curly brackets get changed into the proper data from the database?

and what do the bits in square brackets and the bits with several chevrons mean?

Hello,

It's worth mentioning that my PHP knowledge is basically 0 so I'm not 100% sure when it comes to PHP.

PHP is run on the server side so when someone requests a page that PHP will fetch the data from the database and display it in HTML. On your examples the variables are wrapped in HTML which is used to style it.

I'm not too sure about the square brackets but hopefully someone will be able to clarity that for us.

Jack
 
.tpl files can be considered template files in essence.

This blog post can explain this function for you better than I can. Written by another member here, suarve (from memory).
 
1. & 4.
The "three chevrons", or three less-thans, means "treat everything up to the character string 'HTML' as a string" and in this case, print it to the browser. It's a way of having multi-line strings. It's also a rubbish construct, but never mind. Consider:
Code:
print "line 1";
print "line 2";
print "line 3";

well the <<< construct would turn that into

Code:
print <<<ANYTHING
line 1
line 2
line 3
ANYTHING;

Basically. Print everything you find (as in, don't treat it as code) until you encounter whatever string appears immediately after the <<< again.

2.
You'd have to dig around in some PHP files to figure out where this was replaced and where the data it was replaced with came from.

3.
Is it the float:right; you need explaining?

4.
See above, it's the termination of the previous "print <<<" statement, so printing stops on this line and PHP resumes trying to execute the remaining lines as PHP code.

5.
Same as 1. again.
 
Back
Top Bottom