S
S
serg_astashin2015-09-22 15:23:31
PHP
serg_astashin, 2015-09-22 15:23:31

How to make static pages (similar to the one in dl)?

Briefly speaking. The point is simple. I want the site to have multiple pages. There is a simple code

<?php
$html = file_get_contents( '../templates/default/main.tpl' );
$html = str_replace( '{TITLE}', $title, $html );
$html = str_replace( '{CONTENT}', $content, $html );
$html = str_replace( '{LOGIN}', $login, $html );
$html = str_replace( '{INFO}', $info, $html );
$html = str_replace( '{PAGE}', $page, $html );
$html = str_replace( '{REG}', $reg, $html );
echo $html;
?>

Variables are set something like this:
$info = include(here/path);
It is necessary:
​​1. To be able to make static pages, as in dl (that is, to create a page and display the main tpl on it only instead of the content-page tag (by the way, there will be several pages).
2. To make the tags work in any file from the folder with the template. That is, not like now, only on the main, but also in other templates (reg, info, etc.)
3. Well, so that you can register and enter through static pages (that is, this there would be pages where you can just write {REG} and insert the reg.tpl template
.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Zelensky, 2015-09-22
@SergeyZelensky-Rostov

scatter everything over tpl files, and then include where you need to display a specific block,
for example, like this

<?php
function render($mainTpl, $Content)
{
  if(file_exists($mainTpl)){
    include $mainTpl;
  }
}
?>

maintpl.tpl
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <? include $content; ?>
</body>
</html>

и вызываем 
render( '.../maintpl.tpl','.../reg.tpl');
render( '.../maintpl.tpl','.../reg.tpl');
это самый простой способ но все же он лучше чем str_replace
но его можно развить и сделать очень удобным

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question