MigxPageConfigurator
The component was designed for more flexible content management in the admin: letting non-HTML users reorder blocks, build new templates from existing blocks, and add customization options. During implementation it became clear that the same steps kept repeating: extracting chunks, writing snippet calls, moving content into the manager. So the component was extended to automate those routines. It now works as follows:
- Put shared HTML into a wrapper file.
- Split the rest of the HTML into template files.
- Mark each template file and the wrapper with special attributes (see below).
- Run a script:
slice_tpl.phpfor the wrapper,mgr_tpl.phpfor template files. - Optionally use
mgr_elems.phpto create site elements: plugins, snippets, TVs, resources.
Additional features:
- Built-in lazy-load with image cropping.
- Form management from the admin.
Markup attributes
If you use an IDE, copy assets/components/migxpageconfigurator/css/mpc.css to your machine so the IDE can suggest available attributes during markup.
Осторожно
All attributes use the prefix data-mpc-
sff— used withdata-mpc-formto set preset parameters in the admin.copy— used withdata-mpc-sectionwhen this section is a copy of a section from another template; value should be the original section file name.symbol— used withdata-mpc-snippetordata-mpc-parsewhen the call must run at pre-parse stage; values:{or##; default##.form— used withdata-mpc-chunkto replace the chunk with a call to snippetAjaxFormitLogin.preset— used withdata-mpc-formordata-mpc-snippet; for snippets you can pass preset via|; value is the parameter array key; for forms — parameters of snippetAjaxFormitLogin.cond— used withdata-mpc-itemto output Migx field items by condition; value is a condition using$i(iteration index) or$l(last iteration); with nested Migx, variables get indices by level; only comparison operators encoded with urlencode() are allowed (phpQuery limitation).static— used withdata-mpc-sectionwhen the section is static (same on all pages).name— used withdata-mpc-sectionordata-mpc-formfor a human-readable section or form name.item— on the HTML element that holds field values for Migx configs; must be insidedata-mpc-field(index allowed).unwrap— used withdata-mpc-chunkordata-mpc-itemwhen the chunk is only the inner content, without the wrapper tag.section— on the HTML element that is a content section in the page config.snippet— on the element where the snippet call should go; value format: SnippetName|presetName (snippet name as you would call it in Fenom, presetName — key in the parameter array).chunk— on the element whose content should be extracted to a chunk; value is path to the chunk relative to the chunks folder from system settings.include— used withdata-mpc-chunkto replace with{include 'file:path/to/chunk'}.parse— used withdata-mpc-chunkto replace with{$_modx->parseChunk('@FILE path/to/chunk', $params)}; value is a parameter array, e.g.data-mpc-parse="[$id => 1]".remove— on the element to remove from output after processing; oftendata-mpc-fieldordata-mpc-chunkfor nested chunks.attr— for dynamic attributes, e.g.<input type="checkbox" data-mpc-attr="{$checked}">.field— passes value from template to admin; if the element has href or src (link, frame, image), value is taken from that attribute, otherwise from the element content.
Rendering
To avoid slowing the server, configs are parsed either when running mgr_tpl.php or when saving a resource. Parsing means replacing placeholders with values and snippets with their output. Snippets can run on frontend request or at pre-parse stage.
The second option is not suitable for snippets that must run uncached (e.g. AjaxForm, AjaxFormItLogin, mFilter2). If a snippet must run only when the page is requested, its call in the section file must start with ## — do not change this. Do not edit section files directly; change the template file instead. The call format is controlled by data-mpc-symbol: default (when omitted) is ##; if set, use { or ## (with space for IDE). For placeholders available only on the frontend, use ##:
##$placeholder}Caching
During development you may want changes to apply immediately. Set system setting mpc_dev_mode to Yes; then each run of mgr_tpl.php will clear elements/parsed and full site cache. You can also clear cache from the admin header; that clears the component cache too. To clear only the component cache (folder elements/parsed) without the admin, run core/components/migxpageconfigurator/console/clear_cache.php.
Basic terms
template — set of sections for one or more site pages. section — HTML block that is part of a page template, can be reordered, and is made of simpler elements. template resource — resource that is a child of the "Page types" resource and was created by mgr_tpl.
Field description
Section settings
A section has these settings:
id— section ID, unique per page (two identical sections need different ids).section_name— section name for the manager and as the resource sections array key; must be unique per resource; if it differs from the template resource section name, the section will be duplicated.file_name— path to the section file (for maintainers; better to edit via template file and script).pt-lg,pb-lg,pt,pb— spacing between sections (padding); useful when reordering.hide_section— hide section on the page without removing it.copy_from_origin— copy data from the original section in a child of "Page types".is_static— when set, section content is taken from the "Page types" resource (for global sections with the same content on every page).position— section order. If a resource has a template and a template resource exists, sections from the template resource are shown even when the current resource has none. Example: service pages with 3 sections — description (from resource content), pricing (from section), contact form (static). You may only override the pricing section; useposition(e.g.-1) to reorder (e.g. form first).
Section content
Full list of fields is in the Migx GUI: edit config base. Some fields are Migx configs too; they are listed there. Configs config, contacts, and form_list are not section content.
