K4:Реорганизация тэгов
From In-Portal Developers Guide
m (1 версия) |
Current revision (13:03, 16 March 2009) (view source) |
||
Line 1: | Line 1: | ||
{{toc | category = Библиотека тэгов | sortkey = 001.001}} | {{toc | category = Библиотека тэгов | sortkey = 001.001}} | ||
- | |||
- | |||
- | |||
- | + | Currently, the template parser supports to sets of tags: | |
+ | * compatible with XML rules | ||
+ | * incompatible with XML rules | ||
+ | |||
+ | It's strongly recommended to use XML compatible tags because support for non-compatible tags will eventually be turned off. The below table shows compatibility between older style tags and new style: | ||
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! old style || new style |
|- | |- | ||
| | | | ||
Line 45: | Line 46: | ||
|} | |} | ||
- | + | In order to replace the majority of the old tags, the following command must be executed in the root directory of the project: | |
<source lang="bash"> | <source lang="bash"> | ||
find ./ -type f -name "*.tpl" | xargs \ | find ./ -type f -name "*.tpl" | xargs \ | ||
Line 56: | Line 57: | ||
-e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g" | -e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g" | ||
</source> | </source> | ||
- | + | Next, it may be necessary to manually change tags of the following style: | |
- | * <code><inp2:m_if ... /></code> | + | * <code><inp2:m_if ... /></code> to <code><inp2:m_if></code> |
- | * <code><inp2:m_DefineElement /></code> | + | * <code><inp2:m_DefineElement /></code> to <code><inp2:m_DefineElement></code> |
- | + | For attribute tags, the following changes would need to be made: | |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! old style attributes || new style attributes |
|- | |- | ||
| block || render_as | | block || render_as | ||
Line 72: | Line 73: | ||
|} | |} | ||
- | XML | + | XML compatible tags also increase the readability of templates, for example: |
<source lang="xml"> | <source lang="xml"> | ||
<inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" /> | <inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" /> | ||
</source> | </source> | ||
- | + | This structure is simple and intuitive because one understands immediately what's going on. From the tag name DefineElement it's inferred that it's only a declaration and the result/output won't be seen here, and instead will be used somewhere else. | |
As for IF we should use: | As for IF we should use: | ||
Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией: | Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией: | ||
+ | Please start reviewing the code in your templates. It's not always best to replace attribute names, using the following structure instead: | ||
<source lang="php"> | <source lang="php"> | ||
$param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name'); | $param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name'); | ||
</source> | </source> | ||
- | + | which will return an attribute, only if one's passed. | |
- | + | Kostja can help with any questions about this article. |
Current revision
| ||
---|---|---|
Статьи в этой категории | ||
|
Currently, the template parser supports to sets of tags:
- compatible with XML rules
- incompatible with XML rules
It's strongly recommended to use XML compatible tags because support for non-compatible tags will eventually be turned off. The below table shows compatibility between older style tags and new style:
old style | new style |
---|---|
<inp2:m_block name="some_elem"/> element content <inp2:m_blockend/> |
<inp2:m_DefineElement name="some_elem"> element content </inp2:m_DefineElement> |
<inp2:m_if prefix="prefix" function="Tag" param1="1" param2="2"/> true case <inp2:m_else/> false case <inp2:m_endif/> |
<inp2:m_if check="prefix_Tag" param1="1" param2="2"> true case <inp2:m_else/> false case </inp2:m_if> |
<inp2:m_ParseBlock name="..."/> |
<inp2:m_RenderElement name="..."/> |
In order to replace the majority of the old tags, the following command must be executed in the root directory of the project:
find ./ -type f -name "*.tpl" | xargs \ sed -i -e "s/<inp2:m_blockend[^\/>]*[\/]*>/<\/inp2:m_DefineElement>/g" \ -e "s/<inp2:m_block \(.*\)\/>/<inp2:m_DefineElement \1>/g" \ -e "s/<inp2:m_if\(.*\)prefix=\"\(.*\)\"\(.*\)function=\"\(.*\)\"\([^\/>]*\)[\/]*>/<inp2:m_if\1check=\"\2_\4\"\3\5>/g" \ -e "s/<inp2:m_endif[ ]*\/>/<\/inp2:m_if>/g" \ -e "s/<inp2:m_ParseBlock\([^>]*\)>/<inp2:m_RenderElement\1>/g" \ -e "s/\(<inp2:[^>]*\)\$PrefixSpecial_\([^\"]*\)/\1{\$PrefixSpecial}_\2/g" \ -e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g"
Next, it may be necessary to manually change tags of the following style:
-
<inp2:m_if ... />
to<inp2:m_if>
-
<inp2:m_DefineElement />
to<inp2:m_DefineElement>
For attribute tags, the following changes would need to be made:
old style attributes | new style attributes |
---|---|
block | render_as |
block_* | *_render_as |
*_block | *_render_as |
XML compatible tags also increase the readability of templates, for example:
<inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" />
This structure is simple and intuitive because one understands immediately what's going on. From the tag name DefineElement it's inferred that it's only a declaration and the result/output won't be seen here, and instead will be used somewhere else.
As for IF we should use:
Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией: Please start reviewing the code in your templates. It's not always best to replace attribute names, using the following structure instead:
$param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name');
which will return an attribute, only if one's passed. Kostja can help with any questions about this article.