Guys i m using a template for creating a website .Well i m stucked at a point where i want to display user whole profile onto the website.So shd i write a php file separately or shd i write in the html template code itself.
If anybody can help me and provide some links for this type of e.g it will be very helpful indeed
Merging a php code into A template
Page 1 of 112 Replies - 1067 Views - Last Post: 01 February 2011 - 09:05 AM
Replies To: Merging a php code into A template
#2
Re: Merging a php code into A template
Posted 01 February 2011 - 06:48 AM
Always separate your PHP and HTML. Then use an include statement to output the HTML.
#3
Re: Merging a php code into A template
Posted 01 February 2011 - 06:49 AM
Write the html in a separate file, then have the php read it, modify it where necessary and output it. Mixing html and php in one file is asking for trouble.
http://www.dreaminco...ode-separation/
http://www.dreaminco...ode-separation/
#4
Re: Merging a php code into A template
Posted 01 February 2011 - 06:53 AM
You can create your own function in a different PHP file, or in the same file you want to show the profile in.
Then call it in like so:
Homemade functions are your friend
<?php
function ShowProfile()
{
echo'<p>Name: $name</p>
<p>Age: $age</p>
blah blah
Profile picture:<img src="$image">';
}
?>
Then call it in like so:
<body> <?php ShowProfile(); ?> </body>
Homemade functions are your friend
#5
Re: Merging a php code into A template
Posted 01 February 2011 - 06:56 AM
K i got it its best to separate both the files agreed one hurdle gone
.But the problem persist after writing the php file how shd i call the file i m still a bit unclear abt it
This post has been edited by Sutirth: 01 February 2011 - 06:57 AM
#6
Re: Merging a php code into A template
Posted 01 February 2011 - 06:57 AM
@: Really not good practice to embed the PHP in your HTML like that.
@: You can use the file_get_contents() function to read in the HTML, or an include statement if you don't need to modify the HTML.
@: You can use the file_get_contents() function to read in the HTML, or an include statement if you don't need to modify the HTML.
#7
Re: Merging a php code into A template
Posted 01 February 2011 - 07:08 AM
Mixing languages is almost never a good idea. I mean, sie können Sprachen alle mischen, die Sie mögen, but who's going to read it? Probably not even you after you've been away from it for a while.
#8
Re: Merging a php code into A template
Posted 01 February 2011 - 07:18 AM
Hmm so i guess when i m logging in with a member on a website using "session" and when the login is successful i can directly link the user to its user profile page by using header(userpage) in login script and while in html page of userpage i just need to include the php file and wolaa it will work ryte?? and m i correct in this thinkin process???
#9
Re: Merging a php code into A template
Posted 01 February 2011 - 07:22 AM
You shouldn't be including the PHP in the HTML. Quite the opposite. Treat the PHP as the code you are working with, and the HTML as plaintext to output.
#10
Re: Merging a php code into A template
Posted 01 February 2011 - 07:33 AM
This is why I think beginners should learn another language like C/C++ before starting with php. Those languages don't let you mix output with code, so they require you to do things the proper way. PHP gives you plenty of rope to hang yourself with.
#11
Re: Merging a php code into A template
Posted 01 February 2011 - 08:09 AM
Hmm got it i will make 2 separate files for sure but just wanted to know how to link them so as to my output will be visible on the template that i m using
@Ctphpnwb already done with C and C++ and Java wanna get a good hand on php so learning it
@Ctphpnwb already done with C and C++ and Java wanna get a good hand on php so learning it
#12
Re: Merging a php code into A template
Posted 01 February 2011 - 08:33 AM
Honestly, I don't know what you mean by template. From a php perspective every html file is a template.
As for linking them, you don't, at least not in the sense that you do with C/C++. HTML is simply data to be manipulated, like any text file. Read it in, make your changes, and then send it to the browser. If you don't need to make changes to it, send it to the browser directly by using an include.
Code separation is important whether if you're using MVC or not. MVC requires it, but all code needs it.
As for linking them, you don't, at least not in the sense that you do with C/C++. HTML is simply data to be manipulated, like any text file. Read it in, make your changes, and then send it to the browser. If you don't need to make changes to it, send it to the browser directly by using an include.
Code separation is important whether if you're using MVC or not. MVC requires it, but all code needs it.
#13
Re: Merging a php code into A template
Posted 01 February 2011 - 09:05 AM
Myself i prefer something like this.
<?php
require_once("template.php");
$template = new template("template.html");
$template->set_tag("tag", "whatever i want here!"); // Replaces {tag} from the html template file.
$template->set_tag("tag2", "More stuff in another place!");
$template->replace_tags();
$template->output();
?>
This post has been edited by TMKCodes: 01 February 2011 - 09:07 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote










|