H
H
HitGirl2020-05-07 12:10:03
PHP
HitGirl, 2020-05-07 12:10:03

How to remove php sidebar from html?

Hello!
Can you please tell me if it is possible to remove php-sidebars similar to this one from html-files (index.php):

<?php
                if (isset($login)){
                    echo "<div class='col-xs-6' id='login_text'>
                        <p class='login_text'>Здравствуйте, ".$login."!</p>
                        </div>";
                }
                else{
                    echo "<div class='col-xs-6' id='login_text'>
                        <form action='' method='post' class='login' id='login'>
                        <label>Логин</label><input type='text' name='login' value='".((isset($_COOKIE['gyppi_login']))?$_COOKIE['gyppi_login']:'')."' required>
                        <label>Пароль</label><input type='password' name='password' value='".((isset($_COOKIE['gyppi_password']))?$_COOKIE['gyppi_password']:'')."' required>
                        <input name='button' type='submit' value='Войти'>
                        </form>
                        <button onclick='window.location=\"registration.php\"' class='registration' id='regbutton'>Регистрация</button>".((isset($error_message))?'<div><p class="error_message">'.$error_message.'</p></div>':'')."</div>";
                }
?>

or is it normal to combine html with php and should it be done?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Ivanov, 2020-05-07
@maksim_fix

Banal example:

<html>
<body>
<?=$title?>
Some text
<a href="<?=$link?>">link</a>
</body>
</html>

Something like this, there are also if: endif; constructs that will help in your case, and outputting everything through echo is nonsense

D
di, 2020-05-07
@Delgus

In a simple case, when mvc is used in views, something like this is created

<?php if (isset($login)): ?>
    <div class='col-xs-6' id='login_text'>
        <p class='login_text'>Здравствуйте, <?= $login ?>!</p>
    </div>
<?php else: ?>
    <div class='col-xs-6' id='login_text'>
        <form action='' method='post' class='login' id='login'>
            <label>Логин</label>
            <input type='text' name='login'
                   value='<?= $_COOKIE[' gyppi_login'] ?? $_COOKIE['gyppi_login'] ?>' required>
            <label>Пароль</label>
            <input type='password' name='password'
                   value='<?= $_COOKIE[' gyppi_password'] ?? $_COOKIE['gyppi_password']?>'
                   required>
            <input name='button' type='submit' value='Войти'>
        </form>
        <button onclick='window.location="registration.php"' class='registration' id='regbutton'>Регистрация</button>
        <?php if (isset($error_message)): ?>'
            <div>
                <p class="error_message"><?=$error_message?></p>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>


onclick='window.location="registration.php"'

Such things should also be carried out in js code.
You can also use template generators - Twig, Smarty

N
Northern Lights, 2020-05-07
@php666

or is it normal to combine html with php and should it be done?
if you look at the "compiled" template code of ANY php templater, be it smarty or something newer, you will see that the result is an html template with php inserts. This is absolutely normal.
Well, to an article on this topic.

A
Arseny, 2020-05-25
Matytsyn @ArsenyMatytsyn

1. Displaying footcloths through echo is more expensive for yourself.
2. Template engines like blade, twig prevent (partially) from logic in views (this is important, not to smear logic throughout the project).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question