Manixat Posted March 29, 2013 Share Posted March 29, 2013 (edited) 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 March 29, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/ Share on other sites More sharing options...
jcbones Posted March 29, 2013 Share Posted March 29, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421815 Share on other sites More sharing options...
Christian F. Posted March 29, 2013 Share Posted March 29, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421822 Share on other sites More sharing options...
Manixat Posted March 29, 2013 Author Share Posted March 29, 2013 (edited) 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. 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 March 29, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421825 Share on other sites More sharing options...
Solution Christian F. Posted March 29, 2013 Solution Share Posted March 29, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421826 Share on other sites More sharing options...
Manixat Posted March 29, 2013 Author Share Posted March 29, 2013 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 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! Quote Link to comment https://forums.phpfreaks.com/topic/276295-php-in-html/#findComment-1421828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.