layout: true
Magento User Group: XML and PHTML
--- class: center, middle # XML and PHTML ### within Magento 1 and 2 --- # XML and PHTML - XML types * Configuration * Layout - PHTML * Templating --- class: center, middle # Configuration XML --- # XML global files (m1) * `app/etc/config.xml` * `app/etc/local.xml` * `app/etc/modules/*.xml` * Module files --- # XML global files (m2) * (`config.xml` is substituted with `config.php`) * (`local.xml` is substituted with `env.php`) * (Modules are memorized by autoloader) * `di.xml` * Module files --- # Module files (m1) `app/code/POOL/VENDOR/MODULE/etc/` * `config.xml` * `system.xml` * `adminhtml.xml` --- # Module files (m2) `app/code/VENDOR/MODULE/etc/` (legacy) `vendor/VENDOR/MODULE/etc/` (composer) * `config.xml` * `adminhtml/system/.xml` --- # Configuration XML * Modules * Object aliases (models, blocks, helpers) * Observers & events * Routes (so controllers) * Layout files * Object shortcuts overrides --- # Custom admin theme (m1) `app/etc/local.xml` ```xml
default
foo
``` --- # Fall back themes (m1) `app/design/frontend/foo/default/etc/theme.xml` ```xml
default/modern
updates/foobar.xml
``` --- # Custom admin theme (m2) `vendor/VENDOR/PACKAGE/etc/di.xml` ```xml
VENDOR/PACKAGE
``` --- # Skip auto updates (m1) `app/etc/local.xml` ```xml
1
``` --- # Skip auto updates (m2) There are no auto updates in m2 --- class: center, middle # Layout XML --- # Layout XML Definitions: * Blocks * Handles * Actions on blocks * Updates --- # Block flow -
XML Layout
definition of block
-
Block class
the thing itself
-
PHTML template
output of block (`$this`)
--- # Module path changes m1: `app/design/frontend/VENDOR/PACKAGE/layout/dummy.xml` m2: `app/code/VENDOR/PACKAGE/view/frontend/layout/dummy.xml` `vendor/VENDOR/PACKAGE/view/frontend/layout/dummy.xml` --- # Loading a block (m1) ```xml
``` * `type` = ref to `Mage_Core_Block_Template` * `as` = custom alias * `before` / `after` = alias of other block or `-` * `template` = PHTML template --- # Loading a block (m2) ```xml
``` * `type` = direct class name * (no more class aliassing) * `before` / `after` = `name` of other block or `-` * `template` = PHTML template --- # Referencing a block (m1) ```xml
myfoobar.phtml
``` --- # Referencing a block (m2) ```xml
myfoobar.phtml
``` --- # Adding CSS or JS (m1) `app/design/frontend/VENDOR/PACKAGE/layout/default.xml` ```xml
skin_css
foobar/default.css
js
foobar/default.js
``` --- # Adding CSS or JS (m2) `vendor/VENDOR/PACKAGE/view/frontend/layout/default.xml` ```xml
``` --- # Containers (m2) Formerly blocks of type `core/text_list` ```xml
``` * `htmlTag="div"` * `htmlId="box1"` * `htmlClass="container"` * no template --- # Other changes * `
` is now `
` or `
` * `
` calls now have `
` variables * Practice to add `xsi:type="string"` attribute to arguments * No `local.xml` theming file * No more adding layout files to `etc/theme.xml` https://wiki.magento.com/display/MAGE2DOC/XML+Instructions --- # Tools * Alan Storms CommerceBug * AclReload * AOE Layout Manager * EcomDev LayoutCompiler --- # Quiz * Is block object loaded when XML defines it, but PHTML does not call upon it? --- # Yireo training - June 22nd - Magento 2 Developers Training - July 8th - Magento 2 Theming Training - July 22nd - Magento 2 Technical Merchant - August 19th - PHP Advanced Training - August 26th - Magento Performance Masterclass - October 21st - Magento 2 Seminar