Magento: Add content block at the end of the structual block “content”

前端 未结 1 1319
长情又很酷
长情又很酷 2020-12-31 17:56

I\'m trying to add a content block to Magento, which should be visible on every side below the main content. I want to archive this with a custom extension, so I can copy th

1条回答
  •  情话喂你
    2020-12-31 18:42

    As far as I can see the problem is that you specify your block in the "default" layout handle while most of the content in the "content" block is added by other layout handles which are applied later. That's why the added dependencies in your XML registration file (mentioned by Fabian) are not helping.

    Please consider these two options depending on your needs:

    1. If you really want to include your block on all frontend pages

    In your XML layout file (local.xml or a custom one), add a new layout handle:

    
    
    
        
    
        
            
                
            
        
    
    

    Now you create an event observer to inject your layout handle into your layout:

        getEvent()->getLayout()->getUpdate();
                $layout->addHandle('add_my_block');
                return $this;
            }
        }
    

    Then you register the event observer in your XML extension configuration file (config.xml):

    
    
        
            
                0.0.1
            
        
    
        
            
                
                    
                        
                            singleton
                            mymod/observer
                            addBlockAtEndOfMainContent
                        
                    
                
            
            
        
    
        
            
            
                
                    YourCompany_YourExtension_Model
                
            
        
    
    

    Now your block should end up below the other blocks. I tested this successfully for the homepage, customer login page and category view page. If you have to exclude your block on a few pages, you can check in your event observer if the block should be excluded on that certain page.

    2. If you want to include your block only on some pages

    Add a layout handle to your XML layout file just as we did before but instead of creating and registering an event observer, just tell your XML layout file to use the custom layout handle in some areas:

    
    
    
        
            
        
    
        
            
        
    
        
            
        
    
        
    
        
            
                
            
        
    
    
    

    0 讨论(0)
提交回复
热议问题