Tuesday, October 23, 2012

Function to add variable to drupal template

Use following code to add new variables to Drupal template(page.tpl.php,node.tpl.php etc).

function dpg_preprocess(&$variables, $hook){
    $variables['newvar'] = "New var";
}


function phptemplate_preprocess_node(&$vars){
    $vars['newvar'] = "New var";
}

Thursday, September 20, 2012

PHP 5.4.0 new features:

  1. Support for traits has been added.
  2. Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];.
  3. Function array dereferencing has been added, e.g. foo()[0].
  4. Closures now support $this.
  5. <?= is now always available, regardless of the short_open_tag php.ini option.
  6. Class member access on instantiation has been added, e.g. (new Foo)->bar().
  7. Class::{expr}() syntax is now supported.
  8. Binary number format has been added, e.g. 0b001001101.
  9. Improved parse error messages and improved incompatible arguments warnings.
  10. The session extension can now track the upload progress of files.
  11. Built-in development web server in CLI mode.

Thursday, September 13, 2012

Add new regions into Drupal theme

Add the following line into your theme .info file to add new regions.
To do this go to site->all->themes->your_theme
open your_theme.info and add regions like this
regions[your_region] = Your region description

Now go to page.tpl.php
and add the following code where you want to add region

<?php print render($page['your_region']); ?>

Wednesday, September 12, 2012

Magento: Add Javascript and CSS to Home Page Only

Magento allow you to modify the layout XML specific to that page. So, all you need to do is :

1. Login into Magento admin
2. Go to CMS->static pages
3. Edit home page
4. Go to design tab, in Custom design tab, Add the following code into "Custom Layout Update XML" field to add css or javascript file.
<reference name="head">
  <action method="addItem">
    <type>skin_js</type><script>js/home.js</script>
   </action>
  <action method="addItem">
    <type>skin_css</type><script>css/home.css</script>
   </action>
</reference>

Insert category product into static page magento

To insert category product into static page in magento follow these simple steps.
1. Create a category from Catalog->Manage Categories called "Featured Category".
2. Set this category as active and set "no" to "Include in Navigation Menu" label.
3. Go to display settings tab.
4. Select display mode as static page only.
5. Create static page from CMS->static pages
6. Add the following code into content tab
<code>{{block type="catalog/product_list" category_id="35" template="catalog/product/list.phtml"}}
</code>

How to change home page contents in Magento

To change home page content in Magento do the following steps.
1. Loged in admin of magento.
2. Go to "CMS->pages" menu.
3. Edit "Home page" list item.

Now you can edit home page as per requirement.

How enable template path hints in magento

To enable template path hints in Magento use to following steps.
1. Go to admin->System->configuration.
2. Select "default store view" from "Current Configuration Scope" dropdown from left side menu.
3. Click on developer link on left side menu.
4. Click on debug tab.
5. Uptick "use website"   checkbox and select "Yes" in  "Template Path Hints" rundown.

Congrats you have done it.