<?php
/** @var \Magento\Framework\View\Element\Template $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
/** @var \Magento\Framework\Escaper $escaper */
?>
<?= __('String to translate'); ?>
<?= $block->escapeHtml(__('You will receive a <strong>10% discount on your first purchase</strong> and information about promotions and new products.'), ['strong']) ?>
<?= $block->escapeHtml(__('I agree with the <a href="%1">Privacy Policy</a> and the principles of how we <a href="%2">process data</a>.', $block->getUrl('privacy-policy'), $block->getUrl('process-cookie')), ['a']) ?>
$block->getViewFileUrl('images/loader-1.gif'); - from web/images directory
$block->getViewFileUrl('Magento_Catalog::images/filename.jpg'); - from e.g Magento_Catalog/web/images directory
$block->getUrl('checkout/cart/index');
$block->getUrl('', array('_direct'=>'hairproducts.html'));
$block->getUrl('', array('_direct'=>'hairproducts.html', '_query'=>'manufacturer=412'));
$block->getBaseUrl();
$block->getMediaDirectory();
$block->getChildBlock('block.name');
$block->getChildHtml('block.name');
$block->getChildChildHtml('block.name');
$block->getBlockHtml('block.name');
$block->stripTags(); // removes HTML tags
$block->escapeHtml();
$block->escapeUrl();
$block->escapeHtml('value', $allowedTags);
$block->escapeHtmlAttr('value', $escapeSingleQuote);
$block->escapeJs('value');
$block->escapeUrl($url);
/* @noEscape */
/* @escapeNotVerified */
$block->escapeHtml();
$block->escapeHtml('value', $allowedTags);
$block->escapeUrl();
$block->escapeUrl($url);
$block->escapeHtmlAttr('value', $escapeSingleQuote);
$block->escapeJs('value');
$escaper->...
<?php if($this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('BLOCK_ID')->toHtml() != ''): ?>
<div class="static-block">
<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('BLOCK_ID')->toHtml(); ?>
</div>
<?php endif; ?>
<?= $this->getLayout()->createBlock("Magento\Catalog\Block\Product\Widget\NewWidget")
->setDisplayType("all_products")
->setShowPager(1)
->setProductsPerPage(5)
->setProductsCount(10)
->setPageVarName("pwkvbl")
->setTemplate("product/widget/new/content/new_grid.phtml")
->toHtml(); ?>
<?php $helper = $this->helper(Vendor\Module\Helper\Data::class); ?>
<?php $helper->callMethodName(); ?>
<?= $block->getVar("gallery/width", 'Magento_Catalog'); ?>
<?= $block->getVar("breakpoints/mobile/conditions/max-width", 'Magento_Catalog'); ?>
<?php if($_product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE): ?>
<?php
$deliveryTime = $_product->getResource()->getAttribute('delivery_time');
$minDeliveryTime = $deliveryTime->getFrontend()->getValue($_product);
?>
<div class="delivery-time">
<?php echo __('Delivery time: %1', $minDeliveryTime); ?>
</div>
<?php endif; ?>
$product->getAttributeText('color'); - value as 'text' label
$product->getResource()->getAttribute('color')->getFrontend()->getValue($product); - value as 'text' label
$product->getData('color'); - value as 'id attribute number'
<script>
require(['jquery', 'Magento_Swatches/js/swatch-renderer'], function ($, swatch) {
$(document).on('swatch.initialized', function() {
// Here make some layout changes
});
});
</script>
$this->getLayout()->getUpdate()->getHandles();
<?php $config = $block->getLayout()->createBlock(\Magento\Config\Block\System\Config\Form::class);?>
<?php if($config->getConfigValue('dev/translate_inline/active')): ?>
// do something
<?php endif; ?>
<script type="text/javascript">
require(['jquery', 'matchMedia'], function ($, mediaCheck) {
mediaCheck({
media: '(min-width: 768px)',
// Switch to Desktop Version
entry: function () {
alert('desktop');
},
// Switch to Mobile Version
exit: function () {
alert('mobile');
}
});
});
</script>
<script type="text/x-magento-init">
{
"[data-gallery-role=gallery-placeholder]": {
"mage/gallery/gallery": {
"mixins":["magnifier/magnify"],
"magnifierOpts": <?= $block->getMagnifier() ?>,
"data": <?= $block->getGalleryImagesJson() ?>,
"options": <?= $block->getGalleryOptions()->getOptionsJson() ?>,
"fullscreen": <?= $block->getGalleryOptions()->getFSOptionsJson() ?>,
"breakpoints": <?= $block->getBreakpoints() ?>
}
}
}
</script>
<script>
require(['jquery', 'mage/gallery/gallery'], function ($, gallery) {
$(function () {
$('[data-gallery-role="gallery-placeholder"]').each(function(index, element) {
gallery({
"mixins":["magnifier/magnify"],
"magnifierOpts": <?= $block->getMagnifier() ?>,
"data": <?= $block->getGalleryImagesJson() ?>,
"options": <?= $block->getGalleryOptions()->getOptionsJson() ?>,
"fullscreen": <?= $block->getGalleryOptions()->getFSOptionsJson() ?>,
"breakpoints": <?= $block->getBreakpoints() ?>
}, element);
});
});
});
</script>
ℹ️ <script type="text/lazy">...</script>
is my custom, optimized JS tag call after first user interaction (click, scroll, etc.)
<div class="swiper-container header-slider" data-mage-init='{"Swissup_Swiper/js/swiper": {"loop":true,"centeredSlides":true,"autoplay": {"delay": 10000}, "navigation":{"nextEl":".swiper-button-next","prevEl":".swiper-button-prev"}}}'>
<div class="swiper-wrapper">
<div class="swiper-slide">1</div>
<div class="swiper-slide">2</div>
<div class="swiper-slide">3</div>
</div>
</div>
<script type="text/lazy">
require(['jquery', 'Swissup_Swiper/js/swiper'], function ($, swiper) {
$(function() {
$('.header-slider').each(function(index, element) {
swiper({"loop":true,"centeredSlides":true,"autoplay": {"delay": 10000}, "navigation":{"nextEl":".swiper-button-next","prevEl":".swiper-button-prev"}}, element);
});
});
});
</script>
<script type="text/x-magento-init">
{
"*": {
"Edrone_Magento2module/js/edroneDataTransfer": {}
}
}
</script>
<script type="text/lazy">
require(['jquery', 'Edrone_Magento2module/js/edroneDataTransfer'], function ($, edroneDataTransfer) {
$(function () {
edroneDataTransfer({});
});
})
</script>