bitrix-cms-basics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCMS Basics
CMS基础
Baseline: main 23.0+. Features newer than baseline are marked Since.
Site management layer above the framework — sites, templates, menus, content areas. Landing sites / Sites24: skill .
bitrix-landing基准版本:main 23.0+。晚于基准版本的功能会标记为Since。
位于框架之上的站点管理层——站点、模板、菜单、内容区域。落地页/站点24:技能。
bitrix-landingSites (Multisite)
站点(多站点)
ORM tablet: → table (). Legacy: .
\Bitrix\Main\SiteTableb_langmain/lib/SiteTable.phpCSiteKey fields: (primary, e.g. ), , , , , , , , , .
LIDs1NAMEDIRDOC_ROOTSERVER_NAMESITE_NAMELANGUAGE_IDCULTURE_IDACTIVEDEFphp
$site = \Bitrix\Main\SiteTable::getRow([
'filter' => ['=LID' => SITE_ID],
'select' => ['LID', 'DIR', 'SERVER_NAME', 'DOC_ROOT', 'LANGUAGE_ID'],
]);
$docRoot = \Bitrix\Main\SiteTable::getDocumentRoot(SITE_ID);SITE_IDSITE_DIRSiteTable::getByDomain($host, $directory)ORM表: → 数据库表(文件路径)。旧版用法:。
\Bitrix\Main\SiteTableb_langmain/lib/SiteTable.phpCSite关键字段:(主键,例如)、、、、、、、、、。
LIDs1NAMEDIRDOC_ROOTSERVER_NAMESITE_NAMELANGUAGE_IDCULTURE_IDACTIVEDEFphp
$site = \Bitrix\Main\SiteTable::getRow([
'filter' => ['=LID' => SITE_ID],
'select' => ['LID', 'DIR', 'SERVER_NAME', 'DOC_ROOT', 'LANGUAGE_ID'],
]);
$docRoot = \Bitrix\Main\SiteTable::getDocumentRoot(SITE_ID);SITE_IDSITE_DIRSiteTable::getByDomain($host, $directory)Site Templates
站点模板
Location:
/local/templates/<template_id>//local/templates/mytemplate/
├── header.php
├── footer.php
├── description.php # Template meta ($arTemplate), incl. EDITOR_STYLES
├── styles.css # Content styles — also loaded by the visual editor
├── template_styles.css # Template frame styles (header/footer/grid)
├── .styles.php # Visual editor style list entries
├── components/ # Template-level component overrides
├── page_templates/ # Page layout templates
└── lang/#WORK_AREA#header.phpfooter.php#WORK_AREA#Template selected per site in Admin → Sites → Edit. Prefer , not .
/local/templates//bitrix/templates/存放位置:
/local/templates/<template_id>//local/templates/mytemplate/
├── header.php
├── footer.php
├── description.php # 模板元信息($arTemplate),包含EDITOR_STYLES
├── styles.css # 内容样式——也会被可视化编辑器加载
├── template_styles.css # 模板框架样式(页眉/页脚/网格)
├── .styles.php # 可视化编辑器样式列表条目
├── components/ # 模板级别的组件重写
├── page_templates/ # 页面布局模板
└── lang/#WORK_AREA#header.phpfooter.php#WORK_AREA#每个站点的模板可在管理端→站点→编辑中选择。优先使用,而非。
/local/templates//bitrix/templates/Styles (CSS)
样式(CSS)
Store CSS next to the owner of the markup:
| Owner of markup | Where CSS lives |
|---|---|
Site frame ( | |
| Page content that must be styleable in the visual editor | |
Component template markup ( | |
JS-extension UI loaded via | CSS inside the extension ( |
| One-off page CSS | |
styles.csstemplate_styles.cssstyles.css<head>template_styles.cssVisual editor style list — in the template returns entries (CSS rule itself goes to ):
.styles.phpstyles.cssphp
return [
'example' => [ // array key = CSS class name
'tag' => 'p', // tag(s) the style applies to; comma-separated list allowed
'title' => 'Test style', // name shown in the editor
'html' => '<span style="...">Preview</span>', // optional styled preview
// optional 'section' => groups entries in the editor's style dropdown
],
];Editor-only CSS files — in the template's (): . Loaded only in the visual editor; include them separately for the public site if needed.
EDITOR_STYLESdescription.php$arTemplate'EDITOR_STYLES' => ['/bitrix/css/main/bootstrap.css', ...]Include APIs:
php
$APPLICATION->ShowCSS(); // classic, in header.php <head>: outputs page + template CSS set
$APPLICATION->SetAdditionalCSS('/local/templates/demo/additional.css'); // classic add to that set
\Bitrix\Main\Page\Asset::getInstance()->addCss(SITE_TEMPLATE_PATH . '/styles/page.css');
// 2nd param $additional=true → file goes to the template set, after styles.css / template_styles.css
\Bitrix\Main\UI\Extension::load('demo.product-card'); // extension JS+CSS from its config.phpPrefer (D7) or for new code; / belong to classic site templates.
Asset::addCss()Extension::load()ShowCSS()SetAdditionalCSS()Optimization (Admin → Settings → Product settings → Module settings → Main module): merge CSS files ( option ), use existing versions, gzip copies (, requires zlib). Merge applies only to Asset-registered CSS, is skipped in the admin section and Ajax mode, and can be disabled via . Merged files live in (kernel / / sets) — after editing CSS clear the Bitrix cache (and browser cache) if the old look persists.
mainoptimize_css_files.mincompres_css_js_filesdisableOptimizeCss()/bitrix/cache/css/<SITE_ID>/<template>/template_<hash>page_<hash>将CSS与标记的所属方放在一起:
| 标记所属方 | CSS存放位置 |
|---|---|
站点框架( | 站点模板的 |
| 必须在可视化编辑器中可设置样式的页面内容 | 站点模板的 |
组件模板标记( | 组件模板旁的 |
通过 | 扩展内的CSS( |
| 一次性页面CSS | |
styles.csstemplate_styles.cssstyles.css<head>template_styles.css可视化编辑器样式列表——模板中的返回条目(CSS规则本身需写入):
.styles.phpstyles.cssphp
return [
'example' => [ // 数组键 = CSS类名
'tag' => 'p', // 样式适用的标签;允许多个标签用逗号分隔
'title' => 'Test style', // 编辑器中显示的名称
'html' => '<span style="...">Preview</span>', // 可选的样式预览
// 可选'section' => 在编辑器的样式下拉菜单中对条目进行分组
],
];仅编辑器可用的CSS文件——模板()中的:。仅在可视化编辑器中加载;如果需要在公开站点使用,需单独引入。
description.php$arTemplateEDITOR_STYLES'EDITOR_STYLES' => ['/bitrix/css/main/bootstrap.css', ...]引入API:
php
$APPLICATION->ShowCSS(); // 传统方法,在header.php的<head>中:输出页面+模板的CSS集合
$APPLICATION->SetAdditionalCSS('/local/templates/demo/additional.css'); // 传统方法,添加到该集合中
\Bitrix\Main\Page\Asset::getInstance()->addCss(SITE_TEMPLATE_PATH . '/styles/page.css');
// 第二个参数$additional=true → 文件会被加入模板集合,位于styles.css / template_styles.css之后
\Bitrix\Main\UI\Extension::load('demo.product-card'); // 从扩展的config.php加载扩展的JS+CSS新代码优先使用(D7)或; / 属于传统站点模板用法。
Asset::addCss()Extension::load()ShowCSS()SetAdditionalCSS()优化(管理端→设置→产品设置→模块设置→主模块):合并CSS文件(模块的选项),使用已有的版本,启用gzip压缩(,需要zlib支持)。合并仅对通过Asset注册的CSS生效,在管理端和Ajax模式下会被跳过,也可通过禁用。合并后的文件存放在(内核//集合)——编辑CSS后,如果旧样式仍然存在,需清除Bitrix缓存(以及浏览器缓存)。
mainoptimize_css_files.mincompres_css_js_filesdisableOptimizeCss()/bitrix/cache/css/<SITE_ID>/<template>/template_<hash>page_<hash>Section and Access Files
区域与权限文件
.section.php
.section.php.section.php
.section.phpPer-directory file (walked from current path up to site root). Typical contents:
php
<?php
$sSectionName = 'News';
$arDirProperties = [
'TITLE' => 'News section',
'keywords' => 'news, updates',
'description' => 'Company news',
];- — used for breadcrumbs (
$sSectionName).GetNavChain - — directory properties; read via
$arDirProperties/ merged into$APPLICATION->GetDirProperty().$APPLICATION->GetProperty()
每个目录下的文件(从当前路径向上遍历至站点根目录)。典型内容:
php
<?php
$sSectionName = 'News';
$arDirProperties = [
'TITLE' => 'News section',
'keywords' => 'news, updates',
'description' => 'Company news',
];- ——用于面包屑(
$sSectionName)。GetNavChain - ——目录属性;可通过
$arDirProperties读取 / 合并到$APPLICATION->GetDirProperty()中。$APPLICATION->GetProperty()
.access.php
.access.php.access.php
.access.phpPer-directory file permissions (). Managed by / admin UI. Do not hand-edit unless you know the format; kernel includes it when resolving file rights.
PERM[...]$APPLICATION->SetFileAccessPermission()每个目录下的文件权限()。通过 / 管理端UI管理。除非了解格式,否则不要手动编辑;内核在解析文件权限时会包含该文件。
PERM[...]$APPLICATION->SetFileAccessPermission()Page Properties
页面属性
php
$APPLICATION->SetPageProperty('title', 'About');
$APPLICATION->SetPageProperty('description', 'About the company');
$APPLICATION->SetPageProperty('keywords', 'about');
$title = $APPLICATION->GetPageProperty('title', 'Default');
// GetProperty: page first, then directory (.section.php), then default
$desc = $APPLICATION->GetProperty('description');- /
SetPageProperty— current page only.GetPageProperty - /
SetDirProperty— directory props (often fromGetDirProperty)..section.php - — page → dir → default.
GetProperty
Common keys: , , , plus custom uppercase IDs.
titledescriptionkeywordsphp
$APPLICATION->SetPageProperty('title', 'About');
$APPLICATION->SetPageProperty('description', 'About the company');
$APPLICATION->SetPageProperty('keywords', 'about');
$title = $APPLICATION->GetPageProperty('title', 'Default');
// GetProperty:优先读取页面属性,然后是目录属性(.section.php),最后是默认值
$desc = $APPLICATION->GetProperty('description');- /
SetPageProperty——仅针对当前页面。GetPageProperty - /
SetDirProperty——目录属性(通常来自GetDirProperty)。.section.php - ——页面→目录→默认值。
GetProperty
常用键:、、,以及自定义大写ID。
titledescriptionkeywordsMenus
菜单
- Menu types per site (,
top, …).left - Files: ,
/.top.menu.phpin site root or section./.left.menu.php - Component: .
bitrix:menu
- 每个站点有不同的菜单类型(、
top等)。left - 文件:站点根目录或区域下的、
/.top.menu.php。/.left.menu.php - 组件:。
bitrix:menu
Page Templates
页面模板
/local/templates/<id>/page_templates//local/templates/<id>/page_templates/Include Areas
包含区域
bitrix:main.includephp
$APPLICATION->IncludeComponent('bitrix:main.include', '', [
'AREA_FILE_SHOW' => 'file',
'PATH' => '/include/phone.php',
]);Files typically under or .
/include//local/include/bitrix:main.includephp
$APPLICATION->IncludeComponent('bitrix:main.include', '', [
'AREA_FILE_SHOW' => 'file',
'PATH' => '/include/phone.php',
]);文件通常存放在或下。
/include//local/include/Breadcrumbs
面包屑
- Auto from in
$sSectionNamealong the path..section.php - Manual: .
$APPLICATION->AddChainItem('Title', '/path/') - Component: .
bitrix:breadcrumb
- 自动从路径上的中的
.section.php生成。$sSectionName - 手动设置:。
$APPLICATION->AddChainItem('Title', '/path/') - 组件:。
bitrix:breadcrumb
Users and Groups
用户与组
- ,
CUser— users.\Bitrix\Main\UserTable - Groups control permissions via and group IDs.
\CMain::GetUserRight() - User fields (UF) — ,
CUserTypeEntity; register in module\Bitrix\Main\UserFieldTable; access viaDoInstallin ORM or user fields API.USER.UF_*
- 、
CUser——用户相关。\Bitrix\Main\UserTable - 用户组通过和组ID控制权限。
\CMain::GetUserRight() - 用户字段(UF)——、
CUserTypeEntity;在模块的\Bitrix\Main\UserFieldTable中注册;可通过ORM中的DoInstall或用户字段API访问。USER.UF_*
Admin Panel
管理面板
/bitrix/admin/bitrix-uiCAdminListCAdminForm/bitrix/admin/bitrix-uiCAdminListCAdminFormChecklist
检查清单
- Site-specific code checks /
SITE_ID.SITE_DIR - Template has ; overrides in
#WORK_AREA#./local/templates/ - Site-frame CSS in ; editor-visible content CSS in
template_styles.css(+styles.css); component CSS in the template's.styles.php; new code usesstyle.css/Asset::addCss().Extension::load() - Section meta/breadcrumbs via ; rights via
.section.php/ API..access.php - Page meta via /
SetPageProperty.GetProperty - Menus via or Admin UI; includes for editable fragments.
.menu.php - Landings / composite sites → when applicable.
bitrix-landing
- 站点特定代码检查/
SITE_ID。SITE_DIR - 模板包含;在
#WORK_AREA#中进行重写。/local/templates/ - 站点框架CSS放在中;编辑器可见内容的CSS放在
template_styles.css(+styles.css)中;组件CSS放在模板的.styles.php中;新代码使用style.css/Asset::addCss()。Extension::load() - 区域元信息/面包屑通过设置;权限通过
.section.php/ API设置。.access.php - 页面元信息通过/
SetPageProperty设置。GetProperty - 菜单通过或管理端UI设置;使用包含区域处理可编辑片段。
.menu.php - 落地页/复合站点→适用时使用。
bitrix-landing