Jump to content

Separating Html From Php


jimfog
 Share

Recommended Posts

In my code what i usually do is create divs and inside of them echoing a variable which in turn, has been passed the html code. The variable is included with the usual command in the script. Recently though i came across with another coding scheme. Passing the html in a function and subsequently calling it in the script, after(as the case above) including in the script the file that contains the functions library. I wonder, which coding scheme is better and why, what do you think? Or it is solely a matter of personal preference.?

Link to comment
Share on other sites

Ok, let us forget the template system and the separation issue for a while. From the two above coding schemes which you think is most appropriate and why.

Link to comment
Share on other sites

That's a pretty vague description, I don't use either approach, but I guess a function call would be easier to maintain or make changes to in the future. If you used variables and needed to make changes then you would need to change every place the variable gets set instead of the one function.

Link to comment
Share on other sites

That's a pretty vague description, I don't use either approach...
Ok, what do approach do you use, i am trying to fintd the most efficient way to code in PHP. So far function calls seems to me the best. But i want to hear other opinions also. The template system i assume is for complex CMS like joomla ot drupal-so i am not interested for such a solution since i am not building such thing.
Link to comment
Share on other sites

At the begining i was leaned toward encapsulate in function. But later on i found it is dificult to maintain that later when the aplication began to expand. Then i was look forward to template system like smarty but it seems to me that it is unescecery to get it parse again by template enguine. One of the php feature is php itslelf can be used in html template. MVC like structure will be the best. One for data manupulation and one for visual. In this way you can also separate the backend and frontend which will be effective to maintain and also in collaboration.

Link to comment
Share on other sites

Ok, what do approach do you use, i am trying to fintd the most efficient way to code in PHP. So far function calls seems to me the best.
Well, I use a template system that I made. The code for parsing the templates may be a little inefficient, but it has all of the features I need for the majority of basic websites that I build and it's easy for me to update other sites when I make changes to the template or admin system since they all use the same foundation.
Link to comment
Share on other sites

Is this template system you use based on MVC?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...