G
G
Greg Popov2015-07-27 09:56:59
css
Greg Popov, 2015-07-27 09:56:59

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

2 answer(s)
G
Greg Popov, 2015-08-16
@Gregpopov

/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;
  }

/catalog/view/theme/default/template/common/header.tpl
<?php if ($data['personal_styles']) { ?>
   <link href="<?php echo $data['personal_styles'] ?>" rel="stylesheet" media="all" type="text/css" />
<?php } ?>

The result for the standard template will be:
catalog/view/theme/default/css/account_register.css
(registration page)

O
opencart-russia, 2015-08-10
@opencart-russia

What is the engine version?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question