Views: 1036 (Data available since 06.02.2017)
Last Modified: 20.09.2017
  • Structure
  • Templates
  • Properties
  • Parameters
  • Execution Procedure
  • Structure

    A Page is a PHP file consisting of a prologue, page body (main working area), and epilogue:
    • header
    • workarea
    • footer

    A site page is formed dynamically based on the page template used, data retrieved by the components, and the statistic information located on the page. The creation of site templates and the allocation of components in them are taken care of by site developers.

    Generally all site pages have the following structure:

    • Top header. As a rule, includes the top and left part of the design with a static information (logo, slogan, etc.), top horizontal menu, and left menu (if they are stipulated by design). Dynamic informational materials may be included.
    • Main working area work area. The page working area where the proper informational materials of the site are located. Both a physical file and a dynamic code created by the system based on complex components may be connected as the Main working area.

      If a physical file is connected as the Main working area, such a page is called static. If a dynamic code is connected, such a page is called dynamic.

    • Bottom footer. As a rule, includes a static information (contact details, information about author and owner of the site, etc.), low horizontal menu, and right menu (if they are stipulated by design). Informational materials may be included.

    Note: For more details about the page structure, see the lesson Design Template.

    Top and bottom parts of the design are formed based on the site design template. I.e. the information displayed in these areas is determined by the parameters of the site template.

    Generally, the page structure looks like the following:

    <?
    // prologue connection
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
    ?>
    page body
    <?
    // epilogue connection
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
    ?>

    Thanks to the technology of deferred functions a part of visual elements displayed in the prologue may be set in the page body. These are such elements as:

    The key feature of this technology consists in its possibility to defer the performance of certain functions by performing them in the epilogue, with the results of their performance substituted to the aforementioned code.

    A number of tasks cannot be resolved using the technology of deferred functions, for example when certain actions must be performed in the Prologue with values that in the previous example would be set in the page body (for example, page properties). In this case, the prologue must be divided into a service and a visual part, and the values must be set between them.

    It is achieved as follows:

    <?
    // connection of the service part of the prologue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
    
    // here, for example, a page property may be set
    // using the function $APPLICATION->SetPageProperty
    // and then process it in the visual part of the epilogue
    
    // connection of a visual part of the prologue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_after.php");
    ?>
    Page contents
    <?
    // connection of the epilogue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
    ?>

    The following occurs in the service part of the prologue:

    • Database connection;
    • Execution of agents;
    • Initialization of service constants;
    • Verification of access rights to files and catalogues;
    • Connection of necessary modules;
    • Execution of event handlers OnPageStart and OnBeforeProlog;
    • A number of other necessary actions.

    The service part of the prologue has a particularity that it does not display any data (does not send the header to the browser).

    In the visual part of the prologue the file /bitrix/templates/site template ID/header.php is connected, where site template ID is the identifier of the current site template. This file stores top left part of the current site template.

    The epilogue may also be divided into a visual and a service part:

    <?
    // connection of the service part of the prologue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
    
    // connection of the visual part of the prologue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_after.php");
    
    ?>
    Page contents
    <?
    
    // connection of the visual part of the epilogue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_before.php");
    
    // connection of the service part of the epilogue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
    ?>

    In the visual part of the epilogue the file /bitrix/templates/site template ID/footer.php is connected, where site template ID is the identifier of the current site template. This file stores bottom right part of the current site template. In addition to this, a number of invisible IFRAMEs used by the technology of redirection of visitors is displayed.

    The following occurs in the service part of the epilogue:

    • Sending of mail messages;
    • Execution of event handlers;
    • Database disconnection;
    • A number of other service actions.

    Tasks often occur when there is no need to connect visual parts of the prologue and epilogue. In this case, the connection of service parts of the prologue and epilogue will suffice.

    <?
    // connection of the service part of the prologue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
    ?>
    Page body
    <?
    // connection of the service part of the epilogue
    require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
    ?>

    For the correct operating of the system, the service parts of the prologue and epilogue must be connected.


    Templates

    Page template is a PHP file wherein the contents are strictly consistent with the rules of forming the page structure. The templates may be used to create a new page.

    Page templates are stored in the following catalogs:

    • /bitrix/templates/.default/page_templates/;
    • /bitrix/templates/site template ID/page_templates/.

    Each such catalog may contain the proper page template files and also the service file .content.php of which the principal task is to store descriptions and the procedure for sorting page templates. This information is stored in the $TEMPLATE array of which its structure is presented below:

    Array
    (
        [ ] => Array
            (
                [name] => header of the page template
                [sort] => sorting index
            )
    
    )

    The following algorithm is used during the formation of the list of page templates:

    • Connect site template ID for the current site that connects without PHP condition;
    • Connect the following file one by one:
      • /bitrix/templates/.default/page_templates/.content.php
      • /bitrix/templates/site template ID/page_templates/.content.php
      Each of these files will contain a description of its own $TEMPLATE array. After the connection of these files we will have a single $TEMPLATE array. Then, the following shall be performed for each element of this array which represents a description of one template of a page:
      • Verify physical existence of the page template
      • If it does exist, we add it to the list of templates
    • Sort out the resulting list of templates by sorting index (see $TEMPLATE array structure above).

    Properties

    The section properties are stored in the file .section.php of the relevant catalog (site section). The page properties are set, as a rule, either in the page body or between the service and visual parts of the prologue.

    The section properties are automatically inherited by all subsections and pages of this section. If necessary, you can edit the properties of any separate page of the section by correcting its parameters as needed.

    The following functions are used in work with the properties:

    Property Setting Methods

    CMain::SetPageProperty - sets the page property.

    <?
        $APPLICATION->SetPageProperty("keywords", "web, development, programming");
        ?>

    CMain::SetDirProperty - sets the section property.

    <?
        $APPLICATION->SetDirProperty("keywords", "design, web, site");
        ?>

    Show Property

    CMain::ShowProperty - displays a page or section property using technology of deferred functions.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title><?$APPLICATION->ShowProperty("page_title")?></title>
    </head>
    <body link="#525252" alink="#F1555A" vlink="#939393" text="#000000">
    ...
    

    Get Property Value

    CMain::GetProperty - returns a page or section property.

    <?
        $keywords = $APPLICATION->GetProperty("keywords");
        if (strlen($keywords)>0) echo $keywords;
        ?>

    CMain::GetPageProperty - returns a page property.

    <?
        $keywords = $APPLICATION->GetPageProperty("keywords");
        if (strlen($keywords)>0) echo $keywords;
        ?>

    CMain::GetPagePropertyList - returns an array of all the page properties.

    <?
        $arProp = $APPLICATION->GetPagePropertyList();
        foreach($arProp as $key=>$value)
        	echo '';
        ?>

    CMain::GetDirProperty - returns a section property.

    <?
        $keywords = $APPLICATION->GetDirProperty("keywords");
        if (strlen($keywords)>0) echo $keywords;
        ?>

    CMain::GetDirPropertyList - returns array of section properties collected recursively up to the site root.

    <?
        $arProp = $APPLICATION->GetDirPropertyList();
        foreach($arProp as $key=>$value)
        	echo '';
        ?>

    Working with Meta Tags

    Page and section properties are used to work with meta tags. The following functions are used to work with them:

    CMain::ShowMeta - displays a page property or a section property with an HTML tag frame using a deferred function feature.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <?$APPLICATION->ShowMeta("keywords_prop", "keywords")?>
    <?$APPLICATION->ShowMeta("description_prop", "description")?>
    </head>
    <body link="#525252" alink="#F1555A" vlink="#939393" text="#000000">
    ...
    

    CMain::GetMeta - returns a page property or a section property with an HTML tag frame:

    <?
        $meta_keywords = $APPLICATION->GetMeta("keywords_prop", "keywords");
        if (strlen($meta_keywords)>0) echo $meta_keywords;
        ?>

    Parameters

    Page parameters are intended to translate parameters into module functions in order to change their standard behavior. E.g., if it is necessary to deactivate the memorization of the last page in a session (when using a page by page navigation) or to change a standard data display mode in the functions of the Information Blocks module.

    Page parameters are accessible only within a page. They cannot be saved either in the database or in a session.

    The class CPageOption is intended for working with page parameters.

    Module IDNameParameterDescriptionDefault value
    main Main modulenav_page_in_sessionIf the value is Y, the last open page in a page by page navigation will be memorized in the session; if the value is N, the last page will not be memorized.Y
    iblock Information blocksFORMAT_ACTIVE_DATESIf the value is FULL, the dates referring to an element of an information block (fields ACTIVE_FROM and ACTIVE_TO) will be returned in full format (time included); if the value is SHORT in short format (without time).SHORT

    Examples of use:

    <?
    CPageOption::SetOptionString("main", "nav_page_in_session", "N");
    ?>
    <?
    CPageOption::SetOptionString("iblock", "FORMAT_ACTIVE_DATES", "FULL");
    ?>

    Execution Procedure

    General page execution procedure is as follows:

    • Service part of the prologue;
    • Visual part of the prologue;
    • Page body;
    • Visual part of the epilogue;
    • Service part of the epilogue.

    Component and template parameters can be accessed from the component and template program modules as $arParams array. The result of work of the component program module is $arResult array submitted to the component template entry. The regular echo operator streams the resulting HTML code (and it gets incorporated into a proper place within the page).

    During the work on a component and template it is possible to use the functionality of Bitrix Framework modules which, in their turn, may access the product database.



    Courses developed by «Bitrix», Inc.