How to convert $tpl->sub_load_template('sub.tpl')); in the link of type index.php?do=sub

Well, look: http://makar3000.s3.webhost1.ru/panel2/index.php?do=login

A main.tpl and a new template main.tpl . In index.php

 include ("templates.class.php"); $do = $_GET['do']; if ($do == 'login') { include './templates/login.tpl'; } $tpl = new Template; //инициируем класс $tpl->dir = 'templates/'; //задаём местоположение папки с шаблонами $tpl->load_template('main.tpl'); //загружаем каркас $tpl->compile('main'); //собираем шаблон echo $tpl->result['main']; //выводим результат работы $tpl->global_clear(); //очищаем все переменные для возможно следующего шаблона 

But do I need to, when going to index.php?do=login only shows login.tpl .

    3 answers 3

    There are nails, hammer and planks, how to build this ...?

    Look in the direction of the global variable $ _GET. In short, to get something concrete by index.php? Do = sub

    In the index.php file

     if (!empty($_GET['do']) && $_GET['do'] == "sub") { //контент или подключение другово файла, который например загрузит вам шаблон } else { } 
    • No, I tried ... He adds another template to main.tpl and I need to put login or others instead of main - Makar

    uh .... I didn’t drip a little in DLE .. but it’s clear here how to do it:

     include ("templates.class.php"); $tpl = new Template; //инициируем класс $tpl->dir = 'templates/'; //задаём местоположение папки с шаблонами switch($_GET['do']) { case 'login': $tpl->load_template('login.tpl'); //загружаем каркас break; default: $tpl->load_template('main.tpl'); //загружаем каркас } $tpl->compile('main'); //собираем шаблон echo $tpl->result['main']; //выводим результат работы $tpl->global_clear(); //очищаем все переменные для возможно следующего шаблона 

      Until you understand the work of the $ _GET superglobal array, it is better to go further and do not go. Example:

       <?php $var1 = $_GET['keyname']; # if ($var1 == 'home') { echo 'Это домашняя страница'; } elseif ($var1 == 'about') { echo 'А это страница about'; } ?> 

      Look carefully at the code and imagine that $_GET[] is an array, the keyname in the $_GET array is the key of the array, so that this key contains data, we have to assign it to it, but in a slightly different way, like this (open it in the browser on site): имя_этого_скрипта.php?keyname=123 . And with such a record, the $var1 variable in our script will be equal to "123". The key / value pairs in the URL are listed through the characters & (and), example: zxzx.php?kluch1=znachenie1&key2=value123123 From the entry above, we learn that $_GET['kluch1'] is equal to znachenie1, and $_GET['key2'] according to value123123.

      • question on filling how many nested conditions does the construction with if support?) use switch - Drake
      • and the devil knows, I have 10 or 15 enough, more than one condition I usually use, 3-4, therefore IF) - Andrei Arshinov