Answer the question
In order to leave comments, you need to log in
How to add custom styles to Opencart?
Hello. There was such a problem:
You need to add your own styles to each template, I would not want to connect them manually in the template itself, I just want to pull them into the header as needed for the actual page. How to do this?
PS I couldn't find anything suitable on google.
Answer the question
In order to leave comments, you need to log in
/catalog/controller/common/header.php
$route = empty($this->request->get['route']) ? 'common/home' : $this->request->get['route'];
$css_file = str_replace('/', '_', $route) . '.css';
if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/css/' . $css_file)) {
$data['personal_styles'] = 'catalog/view/theme/' . $this->config->get('config_template'). '/css/' . $css_file;
}else{
$data['personal_styles'] = null;
}
<?php if ($data['personal_styles']) { ?>
<link href="<?php echo $data['personal_styles'] ?>" rel="stylesheet" media="all" type="text/css" />
<?php } ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question