I am using Magento 2 I want to display phtml some page only that i need to select backend. How to display selected page only?
class Selectpage implements \Magento\Framework\Option\ArrayInterface{
/**
* @var array
*/
protected $options;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
/**
* @param CollectionFactory $collectionFactory
*/
public function __construct(
CollectionFactory $collectionFactory
) {
$this->collectionFactory = $collectionFactory;
}
/**
* To option array
*
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$this->options = $this->collectionFactory->create()->toOptionIdArray();
}
$extra_pages_list = array(
array(
'value' => 'catalog_category_view',
'label' => 'Category Page',
),
array(
'value' => 'catalog_product_view',
'label' => 'Product Page',
),
array(
'value' => 'checkout_cart_index',
'label' => 'Shoopping Cart',
),
array(
'value' => 'checkout_index_index',
'label' => 'Checkout',
)
);
$allPages = array_merge($this->options,$extra_pages_list);
return $allPages;
}
my.phtml
<?php
$field = $this->getConfigValue('popup/general/page');
$pages = explode(',',$field);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('Magento\Framework\App\Action\Context')->getRequest();
//echo $request->getFullActionName();exit;
$t1 = "default"; /* don't change this */
if ($request->getFullActionName() == 'catalog_category_view') {
$t1 = $request->getFullActionName();
}
elseif($request->getFullActionName() == 'catalog_product_view'){
$t1 = $request->getFullActionName();
}
elseif($request->getFullActionName() == 'checkout_cart_index'){
$t1 = $request->getFullActionName();
}
elseif($request->getFullActionName() == 'checkout_index_index'){
$t1 = $request->getFullActionName();
}
elseif($this->getPageDetails()){
$t1 = $this->getPageDetails();
}
?>
<?php
//$oN = '';
//if(in_array($t1,$this->getOverlayPages())){
//$oN = "one";
// echo "ok";
//echo $t1;
//var_dump($this->getOverlayPages());
/*}
elseif($t1 && in_array($t1,$this->getOverlayPages('two'))){
$oN = "two";
}
elseif($t1 && in_array($t1,$this->getOverlayPages('three'))){
$oN = "three";
}*/
?>
<?php if(in_array($t1,$this->getOverlayPages())):?>
<div style="display:none;" id="OverlayContent">
<div class="overlay-contents">
<h2 class="overlay-title"><?php echo $this->getTitle(); ?></h2>
<?php echo $this->getStaticblockcontent();?>
</div>
</div>
<script>
jQuery(document).ready(function() {
jQuery(document).bind("mouseleave", function(e){
if (e.pageY - jQuery(window).scrollTop() <= 1){
if(!readCookie('<?php echo $this->getCookieName();?>')){ //check cookie
if(!jQuery('.fancybox-wrap').length){
jQuery.fancybox({
'width': '<?php echo $this->getWidth();?>',
'height': '<?php echo $this->getHeight();?>',
'transitionIn': 'fade',
'transitionOut': 'fade',
'showCloseButton': true,
'fitToView' : false,
'autoSize' : false,
'fixed': false,
'href': "#OverlayContent",
'autoCenter': false,
'helpers' : {
'overlay' : {'closeClick': false}
},
'afterClose' : function(){
<?php if($this->getCookieExpireTime()){ ?>
createCookie('<?php echo $this->getCookieName();?>', 1, '<?php echo $this->getCookieExpireTime();?>');
<?php } ?>
}
});
}//cookie check
}
}
});
<?php if(!$this->getCookieExpireTime()){ ?>
eraseCookie('<?php echo $this->getCookieName();?>');
<?php } ?>
});
/**To create cookie**/
function createCookie(name, value, time) {
var time = parseInt(time);
if (time) {
var date = new Date();
date.setTime(date.getTime() + (time * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
/**To read cookie**/
function readCookie(name) {
var nameEQ = escape(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
/**To erase cookie**/
function eraseCookie(name) {
createCookie(name, "", -1);
}
</script>
<?php endif;?>
How to display ** Content ** in selected page's only ?