Чанки

modxcms.com, “Chunks”, public translation into Russian from English More about this translation.

See also 64 similar translations

Translate into another language.

Participants

elastic233 points
MWM27 points
vovanbo27 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next
1 2

Chunks

Чанки

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Chunks are useful for reusing blocks of code or HTML to your sites. Chunks cannot contain any logic directly, although they can contain calls to Snippets that do contain logic.

Чанки предназначены для многократного использования блоков HTML-кода внутри сайта. Чанки не могут содержать логических выражений, однако они могут содержать вызовы сниппетов, которые, в свою очередь, могут содержать логические выражения.

History of edits (Latest: igor23 2 months, 2 weeks ago) §

Usage

Использование

History of edits (Latest: elastic 8 months, 2 weeks ago) §

1. [[$chunkName]]

[[$chunkName]]

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Also, you can pass properties through a Chunk. Say you had a chunk named 'intro' with the contents:

Кроме того, вы можете передавать значения при вызове чанка. Например, у вас есть чанк «intro» с таким содержимым:

History of edits (Latest: alc 4 months, 1 week ago) §

Hello, [[+name]]. You have [[+messageCount]] messages.

Здравствуйте, [[+name]]. У вас [[+messageCount]] сообщений.

History of edits (Latest: elastic 8 months, 2 weeks ago) §

You could fill those values with:

Вы можете заполнить эти значения следующим образом:

History of edits (Latest: alc 4 months, 1 week ago) §

1. [[$intro? &name=`George` &messageCount=`12`]]

[[$intro? &name=`Вова` &messageCount=`12`]]

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Which would output:

В результате вы получите:

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Hello, George. You have 12 messages.

Здравствуйте, Вова. У вас 12 сообщений.

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Processing Chunk via the API

Обработка чанка методами API

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Chunks can be processed from a snippet by the process() function; for example, this code gets the 'rowTpl' Chunk like so:

Чанки могут обрабатываться сниппетами с помощью функции process(); например, это код получает чанк «rowTpl»:

History of edits (Latest: alc 4 months, 1 week ago) §

# <tr class="[[+rowCls]]" id="row[[+id]]">

<tr class="[[+rowCls]]" id="row[[+id]]">

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# <td>[[+pagetitle]]</td>

<td>[[+pagetitle]]</td>

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# <td>[[+introtext]]</td>

<td>[[+introtext]]</td>

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# </tr>

</tr>

History of edits (Latest: elastic 8 months, 2 weeks ago) §

and processes it with an array of properties for all the published Resources, into a table, setting the class to "alt" if is an even row:

и, используя массив свойств всех опубликованных ресурсов, переводит его в таблицу, устанавливая класс "alt" для чётных строк:

History of edits (Latest: MWM 8 months, 1 week ago) §

1. $modx->getCollection('modResource',array('published'));

$modx->getCollection('modResource',array('published'));

History of edits (Latest: elastic 8 months, 2 weeks ago) §

2. $chunk = $modx->getChunk('rowTpl');

$chunk = $modx->getChunk('rowTpl');

History of edits (Latest: elastic 8 months, 2 weeks ago) §

3. $i = 0;

$i = 0;

History of edits (Latest: elastic 8 months, 2 weeks ago) §

4. $output = '';

$output = '';

History of edits (Latest: elastic 8 months, 2 weeks ago) §

5. foreach ($resources as $resource) {

foreach ($resources as $resource) {

History of edits (Latest: elastic 8 months, 2 weeks ago) §

6. $properties = $resource->toArray();

$properties = $resource->toArray();

History of edits (Latest: elastic 8 months, 2 weeks ago) §

7. $properties['rowCls'] = $i % 2 ? '' : 'alt';

$properties['rowCls'] = $i % 2 ? '' : 'alt';

History of edits (Latest: elastic 8 months, 2 weeks ago) §

8.

8.

History of edits (Latest: MWM 8 months, 1 week ago) §

9. $output .= $rowChunk->process($properties);

$output .= $rowChunk->process($properties);

History of edits (Latest: elastic 8 months, 2 weeks ago) §

10. $i++;

$i++;

History of edits (Latest: elastic 8 months, 2 weeks ago) §

11. }

}

History of edits (Latest: elastic 8 months, 2 weeks ago) §

12. return '<table><tbody>'.$output.'</tbody></table>';

return '<table><tbody>'.$output.'</tbody></table>';

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Modifying a Chunk Via the API

Изменение чанка методами API

History of edits (Latest: elastic 8 months, 2 weeks ago) §

Chunks can also be manipulated by the MODx API:

Чанками можно манипулировать с помощью MODx API:

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# <?php

<?php

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# /* create a new chunk, give it some content and save it to the database */

/* создаём новый чанк, присваиваем ему некоторое содержимое и сохраняем в базу данных */

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk = $modx->newObject('modChunk');

$chunk = $modx->newObject('modChunk');

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk->set('name','NewChunkName');

$chunk->set('name','Мой новый чанк');

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk->setContent('<p>This is my new chunk!</p>');

$chunk->setContent('<p>Это мой новый чанк!</p>');

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk->save();

$chunk->save();

History of edits (Latest: elastic 8 months, 2 weeks ago) §

#

//

History of edits (Latest: MWM 8 months, 1 week ago) §

# /* get an existing chunk, modify the content and save changes to the database */

/* получаем существующий чанк, изменяем его содержимое и сохраняем изменения в базу данных */

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk = $modx->getObject('modChunk', array('name' => 'MyExistingChunk'));

$chunk = $modx->getObject('modChunk', array('name' => 'MyExistingChunk'));

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# if ($chunk) {

if ($chunk) {

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk->setContent('<p>This is my existing chunks new content!</p>');

$chunk->setContent('<p>Это новое содержимое для моего чанка!</p>');

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# $chunk->save();

$chunk->save();

History of edits (Latest: elastic 8 months, 2 weeks ago) §

# }

}

History of edits (Latest: MWM 8 months, 1 week ago) §

#

//

History of edits (Latest: MWM 8 months, 1 week ago) §

# /* get an existing chunk and delete it from the database */

/* получаем существующий чанк и удаляем его из базы данных */

History of edits (Latest: elastic 8 months, 2 weeks ago) §
Pages: ← previous Ctrl next
1 2