PHP in tpl ausführen lassen - Eigene Seite

  • Hallo,


    ich würde gerne wissen wie ich PHP in den tpl Dateien ausführen kann. Ich habe mich schon viel mit Google befasst bezüglich Smarty aber diese Codes funktionieren nicht {php} und auch <?php funktioniert nicht. Ich möchte weitere Scripte im Panel benutzen die ich nur via PHP dort rein bekomme. In den eigentlichen PHP Dateien komm ich nicht klar. Also es wird eher ein include. Dann wollte ich mittels PHP ein active Menu einfügen. Ich habe mir das Template komplett geändert und habe auch ein Dropdown Menu welches offen bleiben soll wenn ich diese Seite besuche.


    PHP
    1. <?php if($site=='domain_manage'){ ?> class="active" <?php } ?>


    Mit obigen Code habe ich es bisher immer super lösen können. Nur eben hier nicht. Mit dem eigenen Code von i-mscp


    HTML
    1. <li class="{IS_ACTIVE_CLASS}">

    klappt es leider nicht.


    Dann würde mich noch interessieren ob und wie man eigene Seiten im CP anlegen kann. Also nicht nur eigene Menupunkte sondern wirklich eigene Seiten mit eigenem Inhalt.



    Danke schon mal :)

  • @x8DaMoN3x


    i-MSCP uses its own template engine. It is not smarty. Well, templates are currently not evaluated but you can change that easily.


    In the template engine class, you must just change the following part:


    File /var/www/imscp/gui/library/iMSCP/pTemplate.php (line 511)

    PHP
    1. $fileContent = file_get_contents($this->root_dir . '/' . $fname);


    To


    PHP
    1. // $fileContent = file_get_contents($this->root_dir . '/' . $fname);
    2. // Evaluate template
    3. ob_start();
    4. include($this->root_dir . '/' . $fname);
    5. $fileContent = ob_get_clean();


    Then, once done, restart the imscp_panel service.


    Now any PHP code inside the templates should be evualuated as you expect.
    Note: When developing, don't forget to disable opcache, else, you won't see your changes.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • thanks for your answer. i did everything like you said but now i get an white page without any error messages.


    i changed the file after that i restartet the imscp deamon.


    sorry for my bad english :D

  • Maybe the root dir which must be adjusted. Give me some minutes to try.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • ok thank you :shy:


    PHP
    1. // $fileContent = file_get_contents($this->root_dir . '/' . $fname);
    2. // Evaluate template
    3. ob_start();
    4. include(self::$_root_dir . '/' . $fname);
    5. $fileContent = ob_get_clean();


    i changed the include a little bit and now it works. thank you for the help :thumbup:

    Edited once, last by x8DaMoN3x ().

  • @x8DaMoN3x


    I assumed that you worked with last i-MSCP version 1.2.11. To resume, you are using older version in which root directory is set using static variable while in 1.2.11, it is defined as property ;)

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • ohh my fault sorry. i know i have to update :D i installed 1.1 because of the boxbilling plugin. but now i dont need the boxbilling plugin so i can update to the last version :D
    still thank you for your help :)

  • I'll maybe add that change in 1.2.x. It is already in 1.3.x or aps (don't remember) branch which is under development. ;)

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206