Browsed by
Category: Magento2

Magento 2 Add image in CSS background

Magento 2 Add image in CSS background

First we need to upload image in “app\design\frontend\vendor\theme\web\images” directory then write below code in css file.

background: url(‘@{baseDir}images/icon_cart.png’);

Then run below command in root directory.

– php bin/magento cache:clean
– php bin/magento setup:static-content:deploy

Hope this article is helpful for you.

Magento 2 Get Customer Logged Session

Magento 2 Get Customer Logged Session

Today I have discussed you about Magento 2 Customer login session code. In magento theme development or module development, we need to get customer session on customer related extension. below is code that help you to get customer session in phtml file or block/controller file.

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get(‘Magento\Customer\Model\Session’);
?>
<?php if($customerSession->isLoggedIn()):?>
<a href=”<?php echo $block->getUrl(‘customer/account’); ?>”><?php echo __(‘My Account’); ?></a>
<?php else:?>
<div>
<a href=”<?php echo $block->getUrl(‘customer/account/login’); ?>”><?php echo __(‘Login’); ?></a>
<span class=”pipe”>|</span>
<a href=”<?php echo $block->getUrl(‘customer/account/create’); ?>”><?php echo __(‘Register’); ?></a>
</div>
<?php endif;?>

 

Hope this code may be helpfully for you thanks again.

Magento 2 Get Page URL in PHTML file (Template File)

Magento 2 Get Page URL in PHTML file (Template File)

This article help you to get base url in latest magento 2 version.
<?php echo $block->getUrl(‘custom/index/index’); ?>
<?php echo $block->getBaseUrl(); ?>
Magento get Customer Account Url
<?php echo $block->getUrl(‘customer/account’); ?>
Magento get Customer Login URL
<?php echo $block->getUrl(‘customer/account/login’); ?>
Magento get Customer Register URL
<?php echo $block->getUrl(‘customer/account/create’); ?>
Hope this helps. Thanks.