Answer the question
In order to leave comments, you need to log in
How to connect css to tpl template?
In case of launching a tpl template from a function, css styles are not applied. If you run this template from a browser, everything works.
From function:
From browser:
//index.php
include_once 'Router.php';
function new_template(){
$smarty = new Smarty();
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'templates_c';
$smarty->config_dir = 'configs';
$smarty->cache_dir = 'cache';
return $smarty;
}
$content = Router::process($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
$smarty = new_template();
$smarty->assign('content', $content);
$smarty->display('template-1.tpl');
?>
//template-1.tpl
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Template</title>
<link rel="stylesheet" type="text/css" href="D:/Server/OpenServer/domains/php.loc/templates/style.css">
</head>
<body>
<div class="header">Head</div>
<div>{$content}</div>
<div class="footer">Footer</div>
</body>
</html>
//style.css
.header {
background-color: black;
}
Answer the question
In order to leave comments, you need to log in
<link rel="stylesheet" type="text/css" href="D:/Server/OpenServer/domains/php.loc/templates/style.css">
And what does the img tag in href do for you where you include css?
// Создаем и настраиваем Смарти
$this->smarty = new Smarty();
$this->smarty->compile_check = $this->config->smarty_compile_check;
$this->smarty->caching = $this->config->smarty_caching;
$this->smarty->cache_lifetime = $this->config->smarty_cache_lifetime;
$this->smarty->debugging = $this->config->smarty_debugging;
$this->smarty->error_reporting = E_ALL & ~E_NOTICE;
// Берем тему из настроек
$theme = $this->settings->theme;
$this->smarty->compile_dir = $this->config->root_dir.'/compiled/'.$theme;
$this->smarty->template_dir = $this->config->root_dir.'/design/'.$theme.'/html';
// Создаем папку для скомпилированных шаблонов текущей темы
if(!is_dir($this->smarty->compile_dir))
mkdir($this->smarty->compile_dir, 0777);
$this->smarty->cache_dir = 'cache';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question