In-Portal Developers Guide

This is a wiki-based Developers Guide for In-Portal Open Source CMS. The purpose of this guide is to provide advanced users, web developers and programmers with documentation on how to expand, customize and improve the functionality and the code the In-Portal software. Please consider contributing to our documentation writing effort.

K4:Реорганизация тэгов

From In-Portal Developers Guide

Jump to: navigation, search
Библиотека тэгов Библиотека тэгов
Статьи в этой категории
  • Реорганизация тэгов

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.