Jump to content

Php in HTML ?


Go to solution Solved by Christian F.,

Recommended Posts

Hello freaks,

 

I posted a thread about what is the best way to create a multilingual site a few days ago, where I was given a great idea and now in the process of realizing it I'm encountering a new problem. Whenever a phrase needs to be translated a class method is being called which looks the phrase up in the database and returns the translated version. What the problem is is that I find it kind of impractical and ugly to flood my HTML up with php tags on every phrase. I remember back in the days I was looking at a forum's index code where there were some kind of variables or something that were sitting in place of the text that was displayed on the page. I suspect that to be the thing I'm looking for. Does anyone know anything about it?

Edited by Manixat
Link to comment
https://forums.phpfreaks.com/topic/276295-php-in-html/
Share on other sites

You should separate logic and output.  So all of your processing should go ahead of your HTML.  This is what you are talking about, and the most logical way of coding in PHP.

 

 

<?php
//set your variables:
if(isset($var)) {
 $var = 'This variable has been set!';
}
else {
 $var = 'This variable has not been set!';
}
 
?>
<html>
<body>
<?php echo $var; ?>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421815
Share on other sites

Sounds like you're talking about templating engines. ;)

Twig seems to be the current craze, but there are many others around as well. Some light-weigh, some more complex and feature-complete. What you should go for depends upon your needs, but I'd advice looking at least one feature-complete and one light-weight system.

 

Incidentally enough, PHP is in itself a template language. :P

Link to comment
https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421822
Share on other sites

Sounds like you're talking about templating engines. ;)

Twig seems to be the current craze, but there are many others around as well. Some light-weigh, some more complex and feature-complete. What you should go for depends upon your needs, but I'd advice looking at least one feature-complete and one light-weight system.

 

Incidentally enough, PHP is in itself a template language. :P

 

I googled templating engines but I didn't find anything like that.

 

Fortunately I found a file from that forum I edited a few years back, here's a piece of the code

 

<!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
	<form method="post" action="{S_LOGIN_ACTION}" class="headerspace">
	<h3><a href="{U_LOGIN_LOGOUT}">{L_LOGIN_LOGOUT}</a><!-- IF S_REGISTER_ENABLED -->  •  <a href="{U_REGISTER}">{L_REGISTER}</a><!-- ENDIF --></h3>
		<fieldset class="quick-login">
			<label for="username">{L_USERNAME}:</label> <input type="text" name="username" id="username" size="10" class="inputbox" title="{L_USERNAME}" />
			<label for="password">{L_PASSWORD}:</label> <input type="password" name="password" id="password" size="10" class="inputbox" title="{L_PASSWORD}" />
			<!-- IF S_AUTOLOGIN_ENABLED -->
				| <label for="autologin">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin" /></label>
			<!-- ENDIF -->
			<input type="submit" name="login" value="{L_LOGIN}" class="button2" />
			{S_LOGIN_REDIRECT}
		</fieldset>
	</form>
<!-- ENDIF -->

 

I'm talking about those {L_USERNAME} {L_PASSWORD} {S_LOGIN_REDIRECT} etc. Do you know what those are ?

Edited by Manixat
Link to comment
https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421825
Share on other sites

Yes, they are template engine variables. As for the search, you should probably not have given up after just one failed attempt:

https://duckduckgo.com/?q=php+template+engine

 

 

I gave up after the fifth, the problem was I was searching for HTML template engines :D

 

This doesn't seem as simple as I expected. I guess I'll be giving it some reading and then decide which way to go.

 

Thank you! :)

Link to comment
https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421828
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.