Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Thursday, 29 April 2010

What is node in drupal?

Basically it comes down to this: A node is a single piece of content that is published on a Drupal site.

Cheers!

Wednesday, 21 April 2010

What is Drupal?

Drupal is software that allows an individual or a community of users to easily publish, manage and organize a great variety of content on a website.

Cheers!

Thursday, 1 April 2010

How to add CSS in drupal?

<?php
 // Repeat this line for every CSS file added. 
drupal_add_css(path_to_theme() . '/example.css', 'theme', 'all', TRUE); 
 // Reassemble the $styles snippet to include the new files. 
$styles = drupal_get_css(); 
?>
Enjoy Drupaling.
Cheers!

What are the Pre-Defined Variables that drupal provides?

Available variables

$base_path:
Returns the base URL path of the Drupal installation. At the very least, this will always default to /.
$breadcrumb:
HTML for displaying the breadcrumbs at the top of the page.
$closure:
Needs to be displayed at the bottom of the page, for any dynamic javascript that needs to be called once the page has already been displayed.
$content:
The HTML content generated by Drupal to be displayed.
$css:
An array of all the CSS files for the current page.
$directory:
The directory the theme is located in, e.g.
themes/garland or themes/garland/minelli.
$feed_icons:
A string of all feed icons for the current page.
$footer_message:
The footer message as defined in the admin settings, also the HTML for the footer region.
$head:
HTML as generated by drupal_get_html_head().
$head_title:
The text to be displayed in the page title.
$header:
HTML for the header region.
$help:
Dynamic help text, mostly for admin pages.
$is_front:
True if the front page is currently being displayed. Used to toggle the mission.
$language:
The language the site is being displayed in.
$layout:
This setting allows you to style different types of layout ('none', 'left', 'right' or 'both') differently, depending on how many sidebars are enabled.
$logo:
The path to the logo image, as defined in theme configuration.
$messages:
HTML for status and error messages, to be displayed at the top of the page.
$mission:
The text of the site mission, empty when display has been disabled in theme settings.
$node
(5.x and after only) If you are in page.tpl.php displaying a node in full page view then $node is available to your template.
$onload_attribute:
(4.7 and older only) Onload tags to be added to the head tag, to allow for autoexecution of attached scripts.
$primary_links (array)
An array containing the links as they have been defined in the phptemplate specific configuration block.
$scripts:
(5.x and after only) HTML to load the JavaScript files and make the JS settings available. Previously, javascript files are hardcoded into the page.tpl.php
$search_box:
True(1) if the search box has been enabled.
$search_button_text:
(4.7 and older only)Translated text on the search button.
$search_description:
(4.7 and older only)Translated description for the search button.
$search_url:
(4.7 and older only)URL the search form is submitted to.
$secondary_links (array):
An array containing the links as they have been defined in the phptemplate specific configuration block.
$sidebar_left:
The HTML for the left sidebar.
$sidebar_right:
The HTML for the right sidebar.
$site_name
The name of the site, empty when display has been disabled in theme settings.
$site_slogan:
The slogan of the site, empty when display has been disabled in theme settings.
$styles:
Required for stylesheet switching to work. This prints out the style tags required.
$tabs:
HTML for displaying tabs at the top of the page.
$title:
Title, different from head_title, as this is just the node title most of the time. Enjoy Drupaling. Cheers!

Wednesday, 31 March 2010

Check out who else current user is logged in?

<?php
if ($GLOBALS['user']->uid) 
{
 
  echo $GLOBALS['user']->uid;
 
} ?>
 
 
Enjoy Drupaling.
Cheers!
 

How to make search enginers compatible URL in drupal?

Use PathAuto and Path Redirect together to redirect old aliases to the new ones.
Search engines will use each page as a single page.

Enjoy Drupaling!

Cheers!

Friday, 26 March 2010

How to add js in drupal?

Use the following code to add js in drupal:
 
<?php
 
// This will add a JS file to your head (specifically the $scripts variable in page.tpl.php)
 
drupal_add_js(drupal_get_path('module', 'my_module') . '/my_module.js');

 
// This add inline JS to the head of the document
 
drupal_add_js('alert("Hello!")', 'inline');

 
// This will add variables in the Drupal.settings object
 
drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');?>
 
Enjoy Drupaling!
Cheers!

Wednesday, 24 March 2010

How to fetch query parameters?

Suppose, following link in a address bar:

http://localhost/drupal/?q=user/1


to fetch query parameters, we will use argument methods.

print arg(0); // this will print 'user'
print arg(1); // this will print '1'

Keep Drupaling!

Cheers!

Tuesday, 23 March 2010

How to setup/customize offline site page?

Go to Administer -> Site Configuration -> Site Maintenance

Select Site status:off - line

and give the content which you want to show.

If you want to customize this page. create maintenance-page.tpl.php and keep this file into theme folder which you using.

Keep Drupaling!

Cheers!

Search is not working properly?

To make search workable, you just go through the following:

set up your cron file or run manually.

you can find cron file at:

http://localhost/drupal_latest/cron.php

run this file from address bar and your search will start working.

Enjoy Drupaling!

Cheers!

How to create Custom Block?

Following is a simple example of custom block. For more information on blocks in general,
see the Blocks page of the handbook.
Adding A 'Contact Information' Block
A business or support group should always let people know how to contact them. One easy
thing is to include your mailing address on your pages. This is about the easiest kind of
block to start with.
1. Go to Administer>>Site building>>Blocks. It should already be sitting on your default theme, but if not, select the right one.

2. Click on the "Add block" tab.

3. Fill in the "Description" and "Body." Here's a sample body:
Example Organization<br>
The Drupal Cookbook (for beginners) http://drupal.org/book/export/html/120612
19 of 39 25.10.2008 18:42
123 Main St.<br>
Mytown, State Zip<br>
USA<br>
(123) 456-7890

4. Save the block.

5. Now you can "Configure" the block to add the block's title and define it's "Visibility".

6. Follow the Configure link next to the block and enter "Contact Information" as the Block's title.

7. Decide if you want to allow users to turn the block on or off, and, if so, which roles should have that ability. You can leave this with no changes to allow everyone to see it. Then choose which pages it will be shown on; Leave this empty to show the block on all pages.

8. Save the block.

9. Now you're back on the block list. Find the block you just created in the list and choose a "Region". You can use the "Weight" parameter to set its position with in the selected area; again, I like the address at the bottom, so I use a heavier weight.

10. Click on the "Save blocks" button.


and done.

Enjoy Drupaling !

Cheers!

How to create pages for "Page Not Found" and "Access Denied"?

Just go to "Create content" and select "Page." I title them "Access Denied" and "Page Not
Found
" but you can call them whatever makes sense to you and your users. When you
submit them, note the node ids. Then go to Administer >> Site Configuration >> Error Reporting  and
enter "node/__" in the appropriate boxes.

Suppose for Access Denied page node id is 8 and I give content as follows:

<p>We're sorry, but you must have permission to view the page you requested.</p>
<p>&nbsp;</p>
<p>If you are already a registered member of this site, please try <a href="user">logging in</a>.</p>
<p>&nbsp;</p>
<p>If you are not a member, you need to <a href="/join_us">join us</a>.</p>
<p>&nbsp;</p>
<p>If you have any questions about our site or group, please feel free to <a href="/contact">contact us</a>.</p>
<p>&nbsp;</p>
<p>--Webmistress</p>


And for Page Not Found page node id is 9 and I give content as follows:

<p>Sorry! The page you were looking for no longer exists. We redesigned our site and many of the pages have
changed.</p>
<p>&nbsp;</p>
<p>If you are unable to find something on our new site or have a question about our site or services feel free to
<a href="/contact">contact us</a>.</p>
<p>&nbsp;</p>
<p>--Webmistress</p>

Now go to Administer >> Site Configuration >> Error Reporting
Here, assign your content node id and Save Configuration.


So, we will give node/8 for Access denied and node/9 for Page Not Found.


Also, you can create page for both :

Page Not Found: page-node-8.tpl.php

Access Denied: page-node-9.tpl.php

Enjoy Drupaling !

Cheers!

How to Assign different template for Admin?

Go to Administer -> Site Configuration -> Administration Theme

Administration Theme window will be opened and select Administration Theme from the dropdown and done.

Enjoying Drupaling..

Cheers !

How to setup WYSIWYG editor in admin section?

First download WYSIWYG Module and install it from Administer -> Site Building -> Module section.

Now go to the Administer -> Site Configuration -> Wysiwyg

When you click on it, you will see the following screen:

















Here you will see a link TinyMCE (Download)

Click on it and download TinyMce editor and keep it the following location:

Extract the archive and copy its contents into a new folder in the following location:
sites/all/llibraries/tinymce

So the actual library can be found at:
sites/all/llibraries/tinymce/jscripts/tiny_mce/tiny_mce.js

Once, you do the above, you will see the another screen look likes:





















select tinymce from dropdown for both the dropdown and then click on SAVE button.

and done your editor is now working...

Enjoyin Drupaling

Cheers!

Monday, 22 March 2010

How to create front page for drupal site?

Suppose you are using garland theme. So you have to create a file name page-front.tpl.php and keep it in garland folder.

Now whenever you will call your site address like http://www.yoursite.com
page-front.tpl.php will be invoked.

You can enter whatever you want to write into it. //$content

How to create a page specificaly for a particular node type?

Suppose you have create a content type name 'calendar-event'. You have lots of content added into it.
All content will be displayed from node.tpl.php file .

But if you want to create another page for this, you just will have to create a page which name will be node-calendar-event.tpl.php

following code you have to enter into it.

<?php
/*echo "<pre>";
print_r($node);
echo "</pre>";*/

echo $node->type;
echo "<br/>";
echo $node->title;
echo "<br/>";
echo $node->content['body']['#value'];
?>

How to change Forgot Password html

first take view source of Request New Password page and find form_id which is user_pass.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
'user_pass' => array(
'template' => 'user-pass',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_pass(&$vars)
{
/*print '


';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];
   
$tempVar['name']['#title'] = 'User Name or Email Address';
    $tempVar['submit']['#value'] = 'E-mail new password';
   
    $vars['username'] = drupal_render($tempVar['name']);       
    $vars['submit_button'] = drupal_render($tempVar['submit']);
   
    $vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-pass.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username;
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

How to change User Login form

first take view source of user login page and find form_id which is user_login.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
'user_login' => array(
'template' => 'user-login',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_login(&$vars)
{
/*print '

';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];

$tempVar['name']['#title'] = 'User Name';
$tempVar['submit']['#value'] = 'Log In';

$vars['username'] = drupal_render($tempVar['name']);
$vars['userpass'] = drupal_render($tempVar['pass']);
$vars['submit_button'] = drupal_render($tempVar['submit']);
$vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-login.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username;
    ?>   
  </div>
  <div class="field">
    <?php
     print $userpass;
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

How to change User Registration form

first take view source of your registration page and find form_id.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
return array(
'search_theme_form' => array(
'template' => 'search-theme-form',
'arguments' => array('form' => NULL),
),
'user_register' => array(
'template' => 'user-register',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_register(&$vars)
{
/*print '
';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];

$tempVar['name']['#title'] = 'User Name';
$tempVar['submit']['#value'] = 'Create Account';

$vars['username'] = drupal_render($tempVar['name']);
$vars['useremail'] = drupal_render($tempVar['mail']);
$vars['submit_button'] = drupal_render($tempVar['submit']);
$vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-register.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username; // print the password field
    ?>   
  </div>
  <div class="field">
    <?php
     print $useremail; // prints the username field
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

so using the above way, you can change your user registration page template.

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

Ubercart shopping cart is not installing properly?

If you are facing problem to install Ubercart Shopping Cart in drupal, just check it out wether TOKEN module is installed or not.

Without Token Module Ubercart will not perform with its full features.