smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.26k stars 710 forks source link

Can't set TemplateDir #376

Closed serhack closed 7 years ago

serhack commented 7 years ago

Hello, after upgrading of Smarty, I can't set the variable of TemplateDir

Then application showed me a lot of errors because it can't find template file .tpl

URL of application: http://localhost/app/ What application should find http://localhost/app/templates/hello.tpl What application try to find http://localhost/app/hello.tpl

I would set Template dir as "templates" I'm using a Codeigniter Library

mreiche commented 7 years ago

Please provide the source code of your template initialization.

serhack commented 7 years ago

Okay, I will

serhack commented 7 years ago
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Smarty Class
 *
 */

 require_once(APPPATH . 'third_party/smarty/libs/Smarty.class.php');
class Smartie extends Smarty
{

    function __construct()
    {
        parent::__construct();

        $this->setTemplateDir('./template');

        log_message('debug', "Smarty Class Initialized");
    }

    /**
     *  Parse a template using the Smarty engine
     *
     * This is a convenience method that combines assign() and
     * display() into one step.
     *
     * Values to assign are passed in an associative array of
     * name => value pairs.
     *
     * If the output is to be returned as a string to the caller
     * instead of being output, pass true as the third parameter.
     *
     * @access    public
     * @param    string
     * @param    array
     * @param    bool
     * @return    string
     */
    function view($template, $data = array(), $return = FALSE)
    {
        foreach ($data as $key => $val) {
            $this->assign($key, $val);
        }

        if ($return == FALSE) {
            $CI =& get_instance();
            if (method_exists($CI->output, 'set_output')) {
                $CI->output->set_output($this->fetch($template));
            } else {
                $CI->output->final_output = $this->fetch($template);
            }
            return;
        } else {
            return $this->fetch($template);
        }
    }
}
// END Smarty Class
serhack commented 7 years ago

OMG, it works! :D

mreiche commented 7 years ago

What was the reason?

serhack commented 7 years ago

Some variables werent setted