Jun 10, 2012

A single template for different sites

Filled under:

A single template for different sites
Sometimes you need to make some patterns with a slight difference. Say different css-styles, images and other stuff. Everything else: html-structure, configuration, functional - identical.

Often these orders there when you need to create a grid of sites.

To avoid a separate site for each template, you can create the appropriate option in the template, which will switch the "variable" part. Now show how this can be done.

She is given the option, as it is in the file MaxSite CMS Custom / my_options.ini . It is better to specify the type of select (dropdown). For example:

[Enter Site]
options_type = templates
options_key = my_select_site
type = select
description = ""
values = "site1 # site2 # site2"
default = "site1"

We will predetermine the values ​​of options site1 (2.3), which will be the identifier "variable part of the pattern."

Different styles

For the css-style, I strongly recommend use of the LESS, the more that its compiler is already present in MaxSite CMS.

Styles we obtain in var_style.css , which will be automatically compiled by var_style.php .

Find the default / css / less / compiling-less.zip and unpack var_style.php , in your css-directory.

In var_style.php registered compiler LESS, which takes var_style.less . Since we have for each site will have its own less-file, then change the code a little bit compiler that the source file is less-dependent on the option «my_select_site».

Let it be site1.less , site2.less , site3.less , that is, "optsiya.less."

$var_style = mso_get_option('my_select_site', 'templates', 'site1') . '.less';

echo mso_lessc(
    / / less-input file (full path on the server)
    getinfo('template_dir') . 'css/' . $var_style,
...

In var_style.php a function mso_lessc () , passing less-file (variable $ var_style ).

Now var_style.css will be formed, depending on the selected site.

Images

If the template you want to use different images for different sites, you can make a subdirectory in the images for each case. Because the way prescribed in css, then there is no confusion will arise.

Determination in php-files

If you want to change the output to a php-file, for example, components or custom-files, you get an option and this is expose the necessary conditions.

$this_site = mso_get_option('my_select_site', 'templates', 'site1');

if ($this_site == 'site1')
{
    ... code for site1
}


Your class for BODY

In the file custom / my_functions.php can set css-class for the tag BODY .

$this_site = mso_get_option('my_select_site', 'templates', 'site1');

mso_set_val('body_class', $this_site);

Now for the selected site can be set through styles body.site1 .

The difference between this varainta from the css-profiles

CSS-profile mount when all the major styles and overrides the existing one. The same version of the styles are formed strictly under the selected site and there is no need to modify them after.

If one site has some common styles, we can distinguish them in a separate file, and less-connected using @ import.

0 comments:

Post a Comment