Showing posts with label drupal. Show all posts
Showing posts with label drupal. Show all posts

Friday, September 12, 2014

How to make a template file for your custom content type in Drupal 7

So far, all the sites I have made in Drupal (both of them hehe), have had numerous content types, and each node of that type needs to be displayed in it's own theme. By default, it seems, Drupal doesn't have this functionality built in, but luckily it's not hard to add.

Let's say your content type is called "Products" - naturally you would want to name the page template for that content type something like page--products.tpl.php - but without the little hack below, that won't work.

So, to get that to work, make sure you have a template.php file in the root folder of your theme, and then add this code to it:
<?php 
    function nameofyourtheme_preprocess_page(&$vars)
        {
            if (isset($vars['node']->type))
            {
                $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
            }
        } 
?>
Just put the name of your theme in the nameofyourtheme part above (same name as the folder your theme is located in) - this file might have other functions as well, so just add this to the file if it does...

Now, your page--products.tpl.php template will start working and doing its magic.

How to remove line on top of a table in Drupal

This will just be a quick post. Drupal tends to add a gray line at the top of any <table> elements you may have on your page, even if you don't have a border specified. A quick and simple way of getting that annoying line gone is by adding this

table {
  border-collapse: separate !important;
}

to your stylesheet file. Does the trick for me!

Tuesday, June 24, 2014

Drupal Modules I've used so far

For the last 6 months or so I've been working in Drupal, which is one of the top open source content management systems out there. I was kinda thrown in the deep end with it - I had a customer who really wanted me to do their website, and was actually willing to pay me to learn Drupal. So I did. And I'm super impressed with it as a CMS.

It is quite a complicated system to learn from scratch, but not impossible. I silly mistake to make is to assume that you know Drupal if you already know PHP, HTML, JS, CSS and MySQL. Knowledge in those things help, yes, but it's a brand new system to get to know.

Anyway, one thing I really like is that chances are, there's a module for that - this is a very popular saying among Drupal developers - because it's such a popular CMS, there are thousands of developers doing the grunt work and help expand and develop the platform, and as I found with my first big Drupal site, 9 out of 10 times there actually is a module for that!

Here is a list of the modules I used with my first big Drupal site:

Views

This was one of the first modules I needed for my site. If you want to display any kind of data in any kind of way, this is the module to get. And the best part, it is fully theme-able :)

Some ways I used it was to show a random Youtube video on a specific page, or determine how a specific page's info gets rendered. I'll never build a Drupal site without this module.

Video Embed Field

As I just mentioned above, I needed a new content type field for video clips, and this one did the trick just fine. It allows you to add a field to your content type that specifically takes either a Youtube clip or a Vimeo clip. You can also specify things like the whether the video should auto play and things like that.

This also creates a new setting under admin for video styles (similar to image styles).

Webform

My client required various forms with many different fields and various emails that needs to be sent with each submission. Webform was the perfect solution for what I required. You can create as many fields for your form as you want, and then you can use those forms in several ways. For example, you can send a thank you message to the person who filled in their form, specify what the thank you page should be, limit how many times each person can submit a form, etc.

After the form gets submitted, you can create multiple emails that needs to get sent out, each with its own settings, like to and from addresses, subject lines and custom messages, etc.

So, if you need people to fill out a slightly more complex form, get this one, it's great!

Search Config

This module I used to limit which content types and things like that show up in search results. Very handy if you have multiple content types, but only want people to find a specific kind.

There are a few more, but these are the ones I'll always have loaded on my future Drupal sites...