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