1c Bitrix how to install a template. Creating a Bitrix template. Template management. We take out language phrases

Hello friends, this is a continuation of the series of lessons, or rather the fifth lesson on creating a landing page on the CMS 1C-Bitrix.

Since I’ve been recording previous lessons for a long time, let’s re-deploy the platform and transfer there the template we previously worked with.

Register Hosting for 1C-Bitrix

Let's go to the news section, open the article 3 months of free hosting from MAKHOST and copy the promotional code from it (8A93-0ECC-D7AD-4A76). Then go to Makhost and select the CMS hosting menu item, then click on the 1C-Bitrix icon.

Register an account on Makhost
Enter your email, promotional code and voila, we have three months free hosting.




At the next step, we check the completeness of the data and confirm it. After successful registration, we receive an email with a login and password to log into the Hosting panel.




After activating your account, go to PHP settings and change its configuration for 1C-Bitrix.


We set the following parameters:

Display_errors - On
default_charset - "UTF-8"
mbstring.func_overload - 2
mbstring.internal_encoding - "UTF-8"

Then we go to the file manager of our domain and delete all unnecessary files, leaving only the installer.


Launch the 1C-Bitrix installer. Just copy the link from the letter and paste it into the browser line.


Installing the PATTERN from the previous lesson

On this moment we installed blank template Bitrix, for this reason we see a white screen. Go to the administrative part, click on the Content icon -> Files and folders -> bitrix -> templates. Create an empty folder in this directory for the template called “lendtv”. Go to it and download the template from the previous lesson. We unpack it and delete the archive; we won’t need it anymore.


For the template to connect, we need to select it in the settings of the current site. To do this, go to Settings -> Product Settings -> Sites -> List of Sites.


Open the first site, go down to the very bottom and in the “Site Template” item, select the template that we previously copied.


Let's go to home page, reset its cache, and as you can see, the template has successfully connected.


Like this in a simple way You can create your own templates and then transfer them between projects. That's all, in the next lesson we'll look at how to transfer such a template to the local folder.

The lesson was prepared by Denis Gorelov.

In the second article on Bitrix templates, we will talk about managing templates, describe the process of installing a new template, and also tell you how to configure the display of various templates for different pages and sections.

A Bitrix template is a set of PHP files, style files, images, and component templates. All templates are located in the /bitrix/templates/ folder and can be applied as one template to several sites, or several templates to one site. On the page Settings → Product Settings → Website Templates in administrative panel a list of templates available in the system is displayed.

Installing a new template

The Bitrix template is a .tar.gz archive containing all the necessary PHP files, style files, scripts and images. You can install a new template either by simply unpacking the archive into the /bitrix/templates/ folder, or by using the form on the Settings → Product Settings → Site Templates page in the Bitrix administrative panel. On this page you need to click on the Upload template button, select local disk archive with the template and enter the symbolic code of the template.

Figure 1 shows the list of templates in the administrative panel, Figure 2 shows the form for adding a new template.

After downloading the archive, it will automatically be unpacked into the /bitrix/templates/ folder and will be displayed in the list of templates in the admin panel.

When downloading a template, you can select the site to which the template will be applied by default.

Applying a template to the current site

Once the template is downloaded and added to the system, it can be applied to one of the sites. To do this, you need to select the site for which the template should be applied in the administrative panel on the Settings / Product Settings / List of Sites page (Figure 3 shows the list of sites in the admin panel).

The site setup form will open. The last parameters of this form are the site template settings. Here you can select one or more templates to be used for this site.

Conditions for using templates

In order for different templates to be used within the same site under different conditions, you can specify the conditions for using the template on the site setup form. The system provides the following types of conditions: For folder or file, For user groups, Time period, Parameter in URL, PHP expression. Let's look at each of them in more detail:

For a folder or file— this condition should be applied when different templates should be used for different pages and sections. In order for the template to be applied only to the user’s personal account section, the value of this condition should be set to “/personal/” - the path to the section from the root folder in which the section “ is located. Personal Area" If the template should be different only for the page with a 404 error, you should specify “/404.php” as the condition value.

For user groups- a common task when the appearance of the site should be different for managers and ordinary visitors is solved using this type of condition. The property value should be set to a user group, for example, “Content Editors”. A visitor authorized as a user from the Content Editors group will see a different appearance of the site than all other visitors.

Period of timegood example use this condition— New Year's theme for the site. If new year template should be applied on the site during the period of time from December 25 to January 10, you need to specify this range as a value for the condition of the Time period type. After the period ends, the template will automatically change to the default template.

Parameter in URL- This condition type is most often used to create a printable version or to test a template. To create a print template use, you must specify “print=Y” as the condition value of this type. To test a new template, you can specify “test=Y” as a condition - and on any page, if the test parameter equal to Y is passed, the test template will be used.

PHP expression— the value of this condition can be any PHP expression, Bitrix API function.

Site templates are applied according to the sorting index value. If more than one template can be used for a page, the one with the higher sort index will be selected. Therefore, carefully specify the sorting of templates - incorrect placement of sorting indexes can lead to unpleasant errors.

Do not forget that “one should not multiply existing things unnecessarily,” i.e., if some problem can be solved without creating an additional template, then it is better not to create an additional template. This is due to the fact that by copying a template to make minor changes, you force yourself to maintain several identical files and make changes to several templates at the same time.

So, we looked at the process of managing templates: loading a new template into the system, applying a template to a site, conditions for using different templates on a page. In the following articles, we will move directly to creating your own template.

Once again, trying to find a programmer who worked with CMS 1C-Bitrix in my city, I came across a problem...

There are programmers who have worked with various free frameworks like Joomla, WordPress, etc., but when it comes to Bitrix, everyone says: “Oh, it’s paid, why do I need it when there are a bunch of other free ones.” And they don’t want to take on learning something new.

That’s how I started, with the exception of one thing, they immediately showed me how, what and why. But I found the material online and on Habré. Therefore, I’ll start with something simple: like an ordinary programmer with knowledge of PHP and at least basic HTML, CSS, JS, start working with Bitrix.

I won’t talk about the template directory structure, you can read about that. The first thing you have to deal with is the integration of an HTML template on a CMS.

Let's say you have a ready-made HTML template and you need to integrate it with the system. Let's start with installation on the server:

  • Go to the Bitrix website and download the installer;
  • Upload bitrixsetup.php to the server and begin the installation.
    The first thing the installer offers you is to choose an edition:

    Select the distribution you need (usually “Site Management”), if you have a key, enter it and click “Download”. The process has begun...

  • If unpacking was successful, then you see the installation welcome window


  • The next thing that novice programmers encounter is “Required system parameters”, namely:


    To solve this problem, go to the server, open the .htaccess file and find the following lines there

    #php_value mbstring.func_overload 2 #php_value mbstring.internal_encoding UTF-8

    Let's uncomment them. Press F5 and everything works... If it still doesn’t work (and this sometimes happens), then write a request to technical support. hosting support.

  • The next step is installing the database. I don’t think there’s any need to describe it here. So let's move on. If everything is fine, then you will see the Bitrix installation process:


  • We got to the choice of solutions offered by Bitrix. Since we need a clean system without any add-ons, we select “Demo site for developers”

  • Next we are greeted by the standard “Master”


    Using it you can install demo data. We don’t need this, click “Cancel”.

  • This completes the installation stage; we proceed directly to the integration of the template. Go to the administration panel in the “Settings” section. Next, we go down the tree of settings: Product settings - Website templates, click on the “Add template” button


    Opens standard form creating a template.


    Come up with an ID (I usually use main), enter the name of the template. The “Description” field is not required; it is rather made for developers so as not to confuse templates if there are several of them.

    This is where the fun began. Usually a pattern HTML pages as follows:

    ... ... ... ... ...

    The main thing here is to understand what belongs to the template and what to the content part. In this example, the content part begins between the section tag. Therefore, we copy the template into the field “ Appearance website template." Between the tag we insert the service directive #WORK_AREA# . As a result, your template will look like this:

    ... ... ... #WORK_AREA# ...

    If you have CSS, then go to the “Template Styles” tab and paste it there.


    Next, I usually edit files via FTP. Open yours text editor(I use Notepad++, so I won’t write in its example) and go to the server. The entire Bitrix template is located at /bitrix/templates/template_name/, if you have pictures or additional style files, JS scripts, etc., then copy everything to this folder.

    Let's move on to the final part and register all the necessary Bitrix variables. Open the header.php file and start editing. The first thing you need to do is connect the site header output:

    … …

    We also want to see the site admin panel in the public part of the site:

    … … …

    To display the page title, add a function to the corresponding tag. As a result, we get the following file:

    ... ... ...

    By the way, I forgot to say that if there are additional files, be it JS, CSS, favicon, and so on, then in order not to write the full long path /bitrix/…/ there is a special constant SITE_TEMPLATE_PATH . We insert it in the right places:


    - instead of the meta tags, header, and css file connections removed in the head section, we place calls to Bitrix functions that will dynamically generate this data

    We write the entire 3rd part in footer.php
    - add /bitrix/templates// to all relative paths. For example, it was



    
    Top