| Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия |
| wiki:devel:configuration [2025/01/03 16:11] – [Параметры] vladpolskiy | wiki:devel:configuration [2025/01/03 16:55] (текущий) – [Template settings] vladpolskiy |
|---|
| |
| ===== Default Settings ===== | ===== Default Settings ===== |
| Чтобы сделать плагин или шаблон настраиваемым, необходимо предоставить ''lib/plugins/<plugin>/conf/default.php'' который будет содержать настройки по умолчанию, и ''lib/plugins/<plugin>/conf/metadata.php'' который содержит описывающие [[#Configuration Metadata|метаданные конфигурации]] используемые [[plugin:config|диспетчером конфигурации]] для обработки/отображения параметров ((шаблоны аналогичны lib/tpl/<template>/conf/default.php и т.д.)). | Чтобы сделать плагин или шаблон настраиваемым, необходимо предоставить ''lib/plugins/<plugin>/conf/default.php'' который будет содержать настройки по умолчанию, и ''lib/plugins/<plugin>/conf/metadata.php'' который содержит описывающие [[#Configuration Metadata|метаданные конфигурации]] используемые [[wiki:plugin:config|диспетчером конфигурации]] для обработки/отображения параметров ((шаблоны аналогичны lib/tpl/<template>/conf/default.php и т.д.)). |
| |
| <code php> | <code php> |
| |
| |
| ==== Examples ==== | ==== Примеры ==== |
| |
| === ''multicheckbox'' with ''_other'' === | === ''multicheckbox'' с ''_other'' === |
| |
| Let's say initially a plugin uses the syntax: | Предположим, изначально плагин использует следующий синтаксис:x: |
| |
| <code php>$meta['multi'] = array('multicheckbox', '_choices' => array('a','b','c','d'));</code> | <code php>$meta['multi'] = array('multicheckbox', '_choices' => array('a','b','c','d'));</code> |
| |
| this means the multicheckbox will show four choices plus a string input. | это означает, что в поле с несколькими флажками будут отображаться четыре варианта выбора и строковое поле ввода. |
| |
| Let's suppose also that the user inserts one or more extra values not in ''_choices''. | Предположим также, что пользователь вставляет одно или несколько дополнительных значений, отсутствующих в ''_choices''. |
| |
| In the next release of the plugin the author's plugin decides to use the multicheckbox without the extra string, but, in order to be backwardly compatible, adopts: | В следующем выпуске плагина авторский плагин решает использовать multicheckbox без дополнительной строки, но, в целях обратной совместимости, принимает: |
| |
| <code php>$meta['multi'] = array('multicheckbox', '_other' => 'exists', '_choices' => array('a','b','c','d'));</code> | <code php>$meta['multi'] = array('multicheckbox', '_other' => 'exists', '_choices' => array('a','b','c','d'));</code> |
| |
| which means: | что означает: |
| * if the user has inserted comma separated values, they will be printed in the extra string; | * если пользователь ввел значения, разделенные запятыми, они будут напечатаны в дополнительной строке; |
| * otherwise the extra string won't show. | * в противном случае дополнительная строка не будет отображаться. |
| |
| Note also that if the user inserts comma separated values which already exist (or some of them) in ''_choices'' but: | Обратите внимание также, что если пользователь вставляет разделенные запятыми значения, которые уже существуют (или некоторые из них), в ''_choices'': |
| * they are already ticked, then the extra string will be removed and nothing else; | * они уже отмечены, то лишняя строка будет удалена и ничего больше; |
| * they are not already ticked, then the extra string will be removed and the relative value will be ticked. | * если они еще не отмечены, то лишняя строка будет удалена и отмечено относительное значение. |
| |
| ===== Accessing Settings ===== | ===== Доступ к настройкам ===== |
| ====Core Settings==== | ====Основные настройки==== |
| Inside [[xref>inc/init.php]] the configurations settings are read into a [[devel:environment|global array]] ''$conf[]''. When no settings were set, these are read from the default settings file. | Внутри :&13:[[wiki:xref:dokuwiki:inc:init.php|init.php]] настройки конфигурации считываются в [[wiki:devel:environment|глобальный массив]] ''$conf[]''. Если настройки не заданы, они считываются из файла настроек по умолчанию. Вы можете получить доступ к основным настройкам в любом месте, используя ''$conf[]'' массив. |
| You can access the core settings anywhere by using the ''$conf[]'' array. | |
| |
| <code php> | <code php> |
| </code> | </code> |
| |
| ====Plugin settings==== | ====Настройки плагина==== |
| You can access settings in [[plugins]] by using the ''%%$this->%%[[xref>getConf|getConf('<setting>')]]'' method. | Вы можете получить доступ к настройкам [[plugins|плагина]] используя ''%%$this->%% |
| In your plugin class you use: | [[xref>getConf|getConf('<setting>')]]'' метод. |
| | В классе вашего плагина используете: |
| <code php> | <code php> |
| $keyvalue = $this->getConf('key'); | $keyvalue = $this->getConf('key'); |
| </code> | </code> |
| |
| ==== Template settings==== | ==== Настройки шаблона==== |
| In [[templates]] you can use ''[[xref>tpl_getConf|tpl_getConf('<setting>')]]''. | В [[templates| шаблонах]] можно использовать ''[[xref>tpl_getConf|tpl_getConf('<setting>')]]''. |
| <code php> | <code php> |
| $nicetoknow = tpl_getConf('special'); | $nicetoknow = tpl_getConf('special'); |
| |
| |
| ===== Labels in Configuration Manager ===== | ===== Метки в диспетчере конфигураций ===== |
| For every setting in ''lib/plugins/<your plugin>/conf/default.php'' there can be a ''%%$lang[<setting>]%%'' value defined in ''lib/plugins/<your plugin>/lang/en/settings.php''. This value will be displayed as the label of the setting in the configuration manager. If the label file is left out or doesn't contain a value for the setting, the configuration manager will display "''%%plugin <plugin name> <setting>%%''" as the label instead. | Для каждого параметра в ''lib/plugins/<your plugin>/conf/default.php'' может быть ''%%$lang[<setting>]%%'' определено значение в ''lib/plugins/<your plugin>/lang/en/settings.php''. Это значение будет отображаться как метка параметра в диспетчере конфигурации. Если файл метки пропущен или не содержит значения для параметра, диспетчер конфигурации отобразит "''%%plugin <plugin name> <setting>%%''" в качестве метки.. |
| |
| You can also create a ''settings.php'' file for other languages. | Вы также можете создать ''settings.php'' файл для других языков. |
| |
| Again, this also applies to templates (see [[:localization]] for further details). | Опять же, это относится и к шаблонам (более подробную информацию см. в [[wiki:localization|Локализация]]). |