Skip to content

Instantly share code, notes, and snippets.

@rattrap
Created April 10, 2015 11:11
Show Gist options
  • Save rattrap/1081b8316896c8e09fc4 to your computer and use it in GitHub Desktop.
Save rattrap/1081b8316896c8e09fc4 to your computer and use it in GitHub Desktop.
Magento ifconfig block and dynamic assets
<?php
/**
* @category Package
* @package Namespace_Package
* @license http://opensource.org/licenses/MIT
* @author Leonard Mocanu <leonard.mocanu@ymail.com>
*/
class Namespace_Package_Helper_Data extends Mage_Core_Helper_Abstract {
/**
* Get link tag
*
* @return string
*/
public function getCssUrl() {
return sprintf('<link rel="stylesheet" href="%s">', $this->_getConfig()->getCssUrl());
}
/**
* Get script tag
*
* @return string
*/
public function getJsUrl() {
return sprintf('<script type="text/javascript" src="%s"></script>', $this->_getConfig()->getJsUrl());
}
/**
* Get the config model
*
* @return Namespace_Package_Model_Config
*/
protected function _getConfig() {
return Mage::getModel('namespace_package/config');
}
}
<?xml version="1.0"?>
<!--
@category Package
@package Namespace_Package
@license http://opensource.org/licenses/MIT
@author Leonard Mocanu <leonard.mocanu@ymail.com>
-->
<layout version="0.1.0">
<!-- HEAD -->
<catalog_product_view>
<reference name="head">
<block type="core/text" name="namespace.package.css">
<action method="setText" ifconfig="namespace_package/enabled_some_block">
<url helper="namespace_package/getCssUrl"></url>
</action>
</block>
<block type="core/text" name="namespace.package.js">
<action method="setText" ifconfig="namespace_package/enabled_some_block">
<url helper="namespace_package/getJsUrl"></url>
</action>
</block>
</reference>
</catalog_product_view>
<!-- //HEAD// -->
<!-- SOME BLOCK -->
<catalog_product_view>
<reference name="product.info.addtocart">
<block type="page/html_wrapper" name="product.info.addtocart.some_block.wrapper" translate="label">
<label>Some Block Wrapper</label>
<block type="namespace_package/product_view_some_block" name="product.info.addtocart.some_block" as="some_block">
<action method="setTemplate" ifconfig="namespace_package/enabled_some_block">
<template>namespace_package/some_block.phtml</template>
</action>
</block>
</block>
</reference>
</catalog_product_view>
<!-- //SOME BLOCK// -->
</layout>
@rattrap
Copy link
Author

rattrap commented Apr 10, 2015

Couldn't add CSS and JS with addItem 'cause they're external.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment