Archive for October, 2016

Magento 2 : Add Custom link in header

Posted: October 29, 2016 in Magento

<block class="Magento\Framework\View\Element\Html\Link\Current" name="test" before="-">
	<arguments>
		<argument name="label" xsi:type="string">Test</argument>
		<argument name="path" xsi:type="string">test</argument>
	</arguments>
</block>
Advertisements

Image in PHTML file:

<img src="<?php echo $this->getViewFileUrl('images/facebook.png'); ?>"/>


Image in Static Block:

{{view url="images/demo.jpg"}} 


Image in CMS page:

{{view url="images/demo.jpg"}} 

Call PHTML file In CMS page:

{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}} 

Call PHTML file in XML:

<referenceContainer name="footer">                
            <block class="Magento\Framework\View\Element\Template" name="footer.hcontent" template="Magento_Theme::html/footer.phtml">
                <container name="hcontent" label="footer content"/>
            </block>
</referenceContainer>

Text in PHTML file:

<?php echo __('Create Backup') ?>

If your string contains a variable, to add a placeholder for this variable in the dictionary, use syntax similar to the following:

<?php echo sprintf(__('Hello %s'), $yourVariable) ?>

In Phtml File:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

in CMS Content:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

In Xml File:

<referenceContainer name="content">
	<block class="Magento\Cms\Block\Block" name="block_identifier">
		<arguments>
			<argument name="block_id" xsi:type="string">block_identifier</argument>
		</arguments>
	</block>
</referenceContainer>