Jump to main content Jump to doc navigation

Блоки с разной вёрсткой через MIGX

Этот урок пошагово показывает, как настроить MIGX для добавления и редактирования блоков с разной вёрсткой.

Пример родился в этом обсуждении.

Задача: система в MODX, где редактор добавляет несколько блоков с разной вёрсткой. В этом случае блоки с одной, двумя или тремя колонками. В каждой колонке изображение, заголовок и контент.

Требования

Сначала установите дополнения для этой настройки:

  • MIGX: создание и заполнение блоков в бэкенде MODX и вывод на фронтенде. ADDON/TinyMCE
  • TinyMCE: richtext-редактор для текстового контента.
  • phpThumbOf: изменение размера изображений под колонки.

Шаблон

Для этого урока создайте новый шаблон с именем MultiColumn.

<html>
    <head>
        <title>[[++site_name]] - [[*pagetitle]]</title>
        <base href="[[++site_url]]" />
        <style>
            /* reset */
            html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
            /* text */
            body{font:13px/1.5 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif}a:focus{outline:1px dotted}hr{border:0 #ccc solid;border-top-width:1px;clear:both;height:0}h1{font-size:25px}h2{font-size:23px}h3{font-size:21px}h4{font-size:19px}h5{font-size:17px}h6{font-size:15px}ol{list-style:decimal}ul{list-style:disc}li{margin-left:30px}p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset{margin-bottom:20px}
            /* fixed: cols 12, rows 4, box_w 80, box_h 80, margin_w 10, margin_h 10, w 960, h 320 */
            .container,.container_12{margin-left:auto;margin-right:auto;width:960px;}.grid_h_1,.grid_h_2,.grid_h_3,.grid_h_4,.grid_h_5,.grid_h_6,.grid_h_7,.grid_h_8,.grid_h_9,.grid_h_10,.grid_h_11,.grid_h_12{position:relative;display:inline;float:left;margin-left:10px;margin-right:10px;}.grid_v_1,.grid_v_2,.grid_v_3,.grid_v_4{position:relative;display:inline;float:left;margin-top:10px;margin-bottom:10px;}.alpha_h{margin-left:0;}.omega_h{margin-right:0;}.alpha_v{margin-top:0;}.omega_v{margin-bottom:0;}.grid_h_1{width:60px;}.grid_h_2{width:140px;}.grid_h_3{width:220px;}.grid_h_4{width:300px;}.grid_h_5{width:380px;}.grid_h_6{width:460px;}.grid_h_7{width:540px;}.grid_h_8{width:620px;}.grid_h_9{width:700px;}.grid_h_10{width:780px;}.grid_h_11{width:860px;}.grid_h_12{width:940px;}.grid_v_1{min-height:60px;}.grid_v_2{min-height:140px;}.grid_v_3{min-height:220px;}.grid_v_4{min-height:300px;}.clear{clear:both;display:block;overflow:hidden;visibility:hidden;width:0;height:0;}.clearfix:after{clear:both;content:' ';display:block;font-size:0;line-height:0;visibility:hidden;width:0;height:0;}* html .clearfix,*:first-child+html .clearfix{zoom:1;}.middle_1{line-height:60px;}.middle_2{line-height:140px;}.middle_3{line-height:220px;}.middle_4{line-height:300px;}
            /*  */
            .box {background:#ccc}
        </style>
    </head>
    <body>
        <div class="container clearfix">
            [[getImageList? &tpl=`@FIELD:MIGX_formname`&tvname=`MultiColumn`]]
            <div class="grid_h_12 grid_v_1">[[*content]]</div>
            <div class="grid_h_12 grid_v_1 middle_1">[^q^] queries, querytime [^qt^], phptime [^p^], totaltime [^t^], source [^s^]</div>
        </div>
    </body>
</html>

Страница предпросмотра

Создайте страницу предпросмотра. С ней можно смотреть блоки в бэкенде без сохранения ресурса.

Создайте в дереве ресурсов новую папку, скрытую из меню. Назовите её MIGX-previews.

Создайте в этой папке ресурс с шаблоном MultiColumn. Назовите его MultiColumn Preview.

MIGX TV

Создайте MIGX TV. Создайте новую TV.

Общая информация

Name

MultiColumn

Параметры ввода

Input-type

migx

Form Tabs

[{
    "formname":"OneCell"
    ,"formtabs": [{
        "caption":"Row Format"
        ,"fields": [{
            "field":"fake"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_2_image"
            ,"caption":"Image"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_2_headline"
            ,"caption":"Headline"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_2_content"
            ,"caption":"Content"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_3_image"
            ,"caption":"Image"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_3_headline"
            ,"caption":"Headline"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_3_content"
            ,"caption":"Content"
            ,"inputTVtype":"hidden"
        }]
    },{
        "caption":"First"
        ,"fields": [{
            "field":"cell_1_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_1_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_1_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    }]
},{
    "formname":"TwoCells"
    ,"formtabs":[{
        "caption":"Row Format"
        ,"fields": [{
            "field":"fake"
            ,"inputTVtype":"hidden"
        },{            "field":"cell_3_image"
            ,"caption":"Image"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_3_headline"
            ,"caption":"Headline"
            ,"inputTVtype":"hidden"
        },{
            "field":"cell_3_content"
            ,"caption":"Content"
            ,"inputTVtype":"hidden"
        }]
    },{
        "caption":"First"
        ,"fields":[{
            "field":"cell_1_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_1_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_1_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    },{
        "caption":"Second"
        ,"fields":[{
            "field":"cell_2_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_2_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_2_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    }]
},{
    "formname":"ThreeCells"
    ,"formtabs":[{
        "caption":"Row Format"
        ,"fields": [{
            "field":"fake"
            ,"inputTVtype":"hidden"
        }]
    },{
        "caption":"First"
        ,"fields": [{
            "field":"cell_1_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_1_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_1_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    },{
        "caption":"Second"
        ,"fields":[{
            "field":"cell_2_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_2_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_2_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    },{
        "caption":"Third"
        ,"fields":[{
            "field":"cell_3_image"
            ,"caption":"Image"
            ,"inputTVtype":"image"
        },{
            "field":"cell_3_headline"
            ,"caption":"Headline"
        },{
            "field":"cell_3_content"
            ,"caption":"Content"
            ,"inputTVtype":"richtext"
        }]
    }]
}]

Во всех наборах formtabs должны быть одни и те же имена полей. Неиспользуемые поля прячьте в hidden. Иначе при переключении formtabs значения пропадут.

Grid Columns

[{
    "header": "Row Format"
    ,"width": "30"
    ,"sortable": "true"
    ,"dataIndex": "MIGX_formname"
},{
    "header": "First"
    ,"width": "160"
    ,"sortable": "false"
    ,"dataIndex": "cell_1_image"
    ,"renderer": "this.renderImage"
},{
    "header": "Second"
    ,"width": "160"
    ,"sortable": "false"
    ,"dataIndex": "cell_2_image"
    ,"renderer": "this.renderImage"
},{
    "header": "Third"
    ,"width": "160"
    ,"sortable": "false"
    ,"dataIndex": "cell_3_image"
    ,"renderer": "this.renderImage"
}]

Preview Url

Укажите полный URL созданного ресурса предпросмотра.

Template Access

шаблон MultiColumns

Чанки

Последний шаг: три чанка для блоков вёрстки.

OneCell

Name

OneCell

Chunk Code
<div class="box grid_h_12 grid_v_4">
    <div class="grid_h_12 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_1_image:phpthumbof=`w=900&h=250&zc=1`]]"/></div>
    <div class="grid_h_12 alpha_h omega_h grid_v_1"><h2>[[+cell_1_headline]]</h2></div>
    <div class="grid_h_12 alpha_h omega_h grid_v_2 omega_v">[[+cell_1_content]]</div>
</div>
<div class="clear"></div>

TwoCells

Name

TwoCells

Chunk Code
<div class="box grid_h_6 grid_v_4">
    <div class="grid_h_6 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_1_image:phpthumbof=`w=460&h=320&zc=1`]]"/></div>
    <div class="grid_h_6 alpha_h omega_h grid_v_1"><h2>[[+cell_1_headline]]</h2></div>
    <div class="grid_h_6 alpha_h omega_h grid_v_2 omega_v">[[+cell_1_content]]</div>
</div>
<div class="box grid_h_6 grid_v_4">
    <div class="grid_h_6 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_2_image:phpthumbof=`w=460&h=320&zc=1`]]"/></div>
    <div class="grid_h_6 alpha_h omega_h grid_v_1"><h2>[[+cell_2_headline]]</h2></div>
    <div class="grid_h_6 alpha_h omega_h grid_v_2 omega_v">[[+cell_2_content]]</div>
</div>
<div class="clear"></div>

ThreeCells

Name

ThreeCells

Chunk Code
<div class="box grid_h_4 grid_v_4">
    <div class="grid_h_4 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_1_image:phpthumbof=`w=300&h=250&zc=1`]]"/></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_1"><h2>[[+cell_1_headline]]</h2></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_2 omega_v">[[+cell_1_content]]</div>
</div>
<div class="box grid_h_4 grid_v_4">
    <div class="grid_h_4 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_2_image:phpthumbof=`w=300&h=250&zc=1`]]"/></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_1"><h2>[[+cell_2_headline]]</h2></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_2 omega_v">[[+cell_2_content]]</div>
</div>
    <div class="box grid_h_4 grid_v_4">
    <div class="grid_h_4 alpha_h omega_h grid_v_1 alpha_v"><img src="[[+cell_3_image:phpthumbof=`w=300&h=250&zc=1`]]"/></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_1"><h2>[[+cell_3_headline]]</h2></div>
    <div class="grid_h_4 alpha_h omega_h grid_v_2 omega_v">[[+cell_3_content]]</div>
</div>
<div class="clear"></div>

Страницы с блоками разной вёрстки

Создайте ресурсы с блоками разной вёрстки.

Создайте новый ресурс. Выберите шаблон MultiColumn. Перейдите на вкладку «Дополнительные поля (TV)».

В MultiColumns-TV нажмите «Add Item» и выберите одну из вёрсток. Заполните поля на вкладках First, Second, Third.

Для предпросмотра нажмите кнопку «Preview».

Чтобы изменить порядок блоков, перетащите элементы в сетке.

Не забудьте сохранить ресурс, когда закончите добавление или правку блоков в MIGX.

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • deJaya
  • JT Skaggs
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$204 per month—let's make that $500!

Learn more