Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with Ronak Chauhan's answer chosen by CommunityBot
Tweeted twitter.com/StackMagento/status/793515063244120065
Notice added Canonical answer required by Magento 2
Bounty Started worth 50 reputation by Magento 2
added 4009 characters in body
Source Link
Magento 2
  • 3.8k
  • 7
  • 55
  • 107
    class Selectpage implements \Magento\Framework\Option\ArrayInterface{

    /**
     * @var array
     */
    protected $options;

    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;

    /**
     * @param CollectionFactory $collectionFactory
     */
    public function toOptionArray__construct()
        {CollectionFactory $collectionFactory
    ) {
        $options$this->collectionFactory = [$collectionFactory;
    }

    /**
     * To option array
   [  *
     * @return array
     */
    public function toOptionArray()
  'label' => __{
        if ('-!$this->options) Please{
 select           $this->options = $this-'>collectionFactory->create(),->toOptionIdArray();
        }
        $extra_pages_list = array(
            array(
                'value' => '''catalog_category_view',
                ]'label' => 'Category Page',
            ),
     [       array(
                'value' => 'catalog_product_view',
                'label' => __('Home'Product PagePage',
 '           ),
            array(
                'value' => '1''checkout_cart_index',
                ]'label' => 'Shoopping Cart',
            ),
     [       array(
                'value' => 'checkout_index_index',
                'label' => __('404'Checkout',
 Page'           ),
            );
        'value'$allPages =>= '2'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'){
  'label'$t1 =>= __$request->getFullActionName('About);
}
elseif($this->getPageDetails()){
 Page' $t1 = $this->getPageDetails();
}

?>


<?php 
  //$oN = '';
  //if(in_array($t1,$this->getOverlayPages())){
    //$oN = "one";
   // echo "ok";
    //echo $t1;
    //var_dump($this->getOverlayPages());
  /*}
  'value'elseif($t1 =>&& '3'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() {       
    'label' => __jQuery('Product'document).bind("mouseleave", function(e){
        if (e.pageY - jQuery(window).scrollTop() <= 1){   
      'value' => '4',if(!readCookie('<?php echo $this->getCookieName();?>')){ //check cookie             
            if(!jQuery('.fancybox-wrap').length){    ],               
                jQuery.fancybox({
[                    'width': '<?php echo $this->getWidth();?>',
                    'label''height': =>'<?php __echo $this->getHeight('Category');?>',
                    'value''transitionIn': =>'fade',
 '5'                   'transitionOut': 'fade',
                ]    'showCloseButton': true,    
                    'fitToView'   : false,
            ];        'autoSize'    : false,
            return $options;       'fixed': false,
                    'href': "#OverlayContent",
                    'autoCenter': false,
                    'helpers'     : { 
                           'overlay' : {'closeClick': false}

layout.xml

                           }, 
                    'afterClose' : function(){
                        <?xmlphp version="1.0"if($this->getCookieExpireTime()){ ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema                           createCookie('<?php echo $this-instance">getCookieName();?>', layout="1column"1, xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">'<?php echo $this->getCookieExpireTime();?>');
    <head>                    <?php } ?>
        <title>Sample Paage</title>           }                        
        <css src="Namespace_Module::css       }); 
                }/mycsss.css"/cookie check                 
            }
        }   
     });  
        <?php if(!$this->getCookieExpireTime()){ ?>
            eraseCookie('<?php echo $this->getCookieName();?>');
        </head>?php } ?>
    });  <body>



/**To create cookie**/
function createCookie(name, value, time) {
var time = parseInt(time);
    if <referenceContainer(time) name="content">{
        var date = new Date();
        date.setTime(date.getTime() + (time * <block60 class="Namespace\Module\Block\Popup\Index"* name="popup_index"60 template="popup/index* 1000));
        var expires = "; expires=" + date.phtml">toGMTString();
    } else var expires = "";
    <document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/block>";
}
/**To read cookie**/
function readCookie(name) {
    </referenceContainer>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;
}
/body>**To erase cookie**/
function eraseCookie(name) {
    createCookie(name, "", -1);
}

   
</page>script>

<?php endif;?>

How to display popup/index.phtml** Content ** in selected page's only ?

enter image description hereenter image description here

    class Selectpage implements \Magento\Framework\Option\ArrayInterface{
        public function toOptionArray()
        {
            $options = [
                [
                    'label' => __('-- Please select --'),
                    'value' => '',
                ],
                [
                    'label' => __('Home Page '),
                    'value' => '1',
                ],
                [
                    'label' => __('404 Page'),
                    'value' => '2',
                ],
                [
                    'label' => __('About Page'),
                    'value' => '3',
                ],
[
                    'label' => __('Product'),
                    'value' => '4',
                ],

[
                    'label' => __('Category'),
                    'value' => '5',
                ],
                
            ];
            return $options;
        }

layout.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Sample Paage</title>
        <css src="Namespace_Module::css/mycsss.css"/>
        
    </head>
     <body>     
        <referenceContainer name="content">         
            <block class="Namespace\Module\Block\Popup\Index" name="popup_index" template="popup/index.phtml">
            </block>
        </referenceContainer>      
    </body>
</page>

How to display popup/index.phtml in selected page's only ?

enter image description here

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 ?

enter image description here

added 506 characters in body
Source Link
Magento 2
  • 3.8k
  • 7
  • 55
  • 107
    class Selectpage implements \Magento\Framework\Option\ArrayInterface{
        public function toOptionArray()
        {
            $options = [
                [
                    'label' => __('-- Please select --'),
                    'value' => '',
                ],
                [
                    'label' => __('Home Page '),
                    'value' => '1',
                ],
                [
                    'label' => __('404 Page'),
                    'value' => '2',
                ],
                [
                    'label' => __('About Page'),
                    'value' => '3',
                ],
[
                    'label' => __('Product'),
                    'value' => '4',
                ],

[
                    'label' => __('Category'),
                    'value' => '5',
                ],
                
            ];
            return $options;
        }

How to display popup/index.phtml in selected page's only ?

enter image description here

class Selectpage implements \Magento\Framework\Option\ArrayInterface{
    public function toOptionArray()
    {
        $options = [
            [
                'label' => __('-- Please select --'),
                'value' => '',
            ],
            [
                'label' => __('Home Page '),
                'value' => '1',
            ],
            [
                'label' => __('404 Page'),
                'value' => '2',
            ],
            [
                'label' => __('About Page'),
                'value' => '3',
            ],
            
        ];
        return $options;
    }
    class Selectpage implements \Magento\Framework\Option\ArrayInterface{
        public function toOptionArray()
        {
            $options = [
                [
                    'label' => __('-- Please select --'),
                    'value' => '',
                ],
                [
                    'label' => __('Home Page '),
                    'value' => '1',
                ],
                [
                    'label' => __('404 Page'),
                    'value' => '2',
                ],
                [
                    'label' => __('About Page'),
                    'value' => '3',
                ],
[
                    'label' => __('Product'),
                    'value' => '4',
                ],

[
                    'label' => __('Category'),
                    'value' => '5',
                ],
                
            ];
            return $options;
        }

How to display popup/index.phtml in selected page's only ?

enter image description here

Post Undeleted by Magento 2
Post Deleted by Magento 2
edited title
Link
Magento 2
  • 3.8k
  • 7
  • 55
  • 107

Magento Custom module phtml file call selected page pnlyonly in system configuration

Source Link
Magento 2
  • 3.8k
  • 7
  • 55
  • 107
Loading