I want to add a class to main div on a template. how can I do that?

You’re probably looking for something like this:

<?php

    function add_classes_to_body_class($classes) {

            // make sure 'page-template.php' matches your template name
            if ( is_page_template('page-template.php') ) {
                $classes[] = 'main';
            }
        return $classes;
    }
    add_filter( 'body_class', 'add_classes_to_body_class' );

?>

make sure you add body_class() into your markup. Traditionally it would be in your body tag like so. <body id="foobar" <?php body_class(); ?>>