Index: /branches/release-36/lib/MT/Blog.pm
===================================================================
--- /branches/release-36/lib/MT/Blog.pm (revision 1971)
+++ /branches/release-36/lib/MT/Blog.pm (revision 2051)
@@ -497,9 +497,7 @@
                                       archive_type => $archive_type});
     return 0 unless @maps;
-    require MT::Template;
+    require MT::PublishOption;
     foreach my $map (@maps) {  
-        my $tmpl = MT::Template->load($map->template_id)
-            or return 0;
-        $result++ if !$tmpl->build_dynamic;
+        $result++ if $map->build_type != MT::PublishOption::DYNAMIC();
     }
     #$result ||= 1 if ($blog->custom_dynamic_templates || '') ne 'custom';
Index: /branches/release-36/lib/MT/CMS/Template.pm
===================================================================
--- /branches/release-36/lib/MT/CMS/Template.pm (revision 2049)
+++ /branches/release-36/lib/MT/CMS/Template.pm (revision 2051)
@@ -1286,36 +1286,56 @@
     $sess_obj->remove if $sess_obj;
 
-    require MT::TemplateMap;
+    my $dynamic = 0;
     my $q = $app->param;
-    my @p = $q->param;
-    for my $p (@p) {
-        if ( $p =~ /^archive_tmpl_preferred_(\w+)_(\d+)$/ ) {
-            my $at     = $1;
-            my $map_id = $2;
-            my $map    = MT::TemplateMap->load($map_id)
-                or next;
-            $map->prefer( $q->param($p) );    # prefer method saves in itself
-        }
-        elsif ( $p =~ /^archive_file_tmpl_(\d+)$/ ) {
-            my $map_id = $1;
-            my $map    = MT::TemplateMap->load($map_id)
-                or next;
-            $map->file_template( $q->param($p) );
-            $map->save;
-        }
-        elsif ( $p =~ /^map_build_type_(\d+)$/ ) {
-            my $map_id     = $1;
-            my $map        = MT::TemplateMap->load($map_id)
-                or next;
-            my $build_type = $q->param($p);
-            require MT::PublishOption;
-            $map->build_type($build_type);
-            if ( $build_type == MT::PublishOption::SCHEDULED() ) {
-                my $period   = $q->param( 'map_schedule_period_' . $map_id );
-                my $interval = $q->param( 'map_schedule_interval_' . $map_id );
-                my $sec      = _get_interval( $period, $interval );
-                $map->build_interval($sec);
-            }
-            $map->save;
+    my $type = $q->param('type');
+    # FIXME: enumeration of types
+    if ( $type eq 'custom'
+      || $type eq 'index'
+      || $type eq 'widget'
+      || $type eq 'widgetset' )
+    {
+        $dynamic = $obj->build_dynamic;
+    }
+    else
+    {
+        # archive template specific post_save tasks
+        require MT::TemplateMap;
+        my @p = $q->param;
+        for my $p (@p) {
+            my $map;
+            if ( $p =~ /^archive_tmpl_preferred_(\w+)_(\d+)$/ ) {
+                my $at     = $1;
+                my $map_id = $2;
+                $map    = MT::TemplateMap->load($map_id)
+                    or next;
+                $map->prefer( $q->param($p) );    # prefer method saves in itself
+            }
+            elsif ( $p =~ /^archive_file_tmpl_(\d+)$/ ) {
+                my $map_id = $1;
+                $map    = MT::TemplateMap->load($map_id)
+                    or next;
+                $map->file_template( $q->param($p) );
+                $map->save;
+            }
+            elsif ( $p =~ /^map_build_type_(\d+)$/ ) {
+                my $map_id     = $1;
+                $map        = MT::TemplateMap->load($map_id)
+                    or next;
+                my $build_type = $q->param($p);
+                require MT::PublishOption;
+                $map->build_type($build_type);
+                if ( $build_type == MT::PublishOption::SCHEDULED() ) {
+                    my $period   = $q->param( 'map_schedule_period_' . $map_id );
+                    my $interval = $q->param( 'map_schedule_interval_' . $map_id );
+                    my $sec      = _get_interval( $period, $interval );
+                    $map->build_interval($sec);
+                }
+                $map->save;
+            }
+            if ( !$dynamic
+              && $map && $map->build_type == MT::PublishOption::DYNAMIC() )
+            {
+                $dynamic = 1;
+            }
         }
     }
@@ -1335,5 +1355,5 @@
     }
 
-    if ( $obj->build_dynamic ) {
+    if ( $dynamic ) {
         if ( $obj->type eq 'index' ) {
             $app->rebuild_indexes(
@@ -1343,10 +1363,30 @@
             ) or return $app->publish_error();    # XXXX
         }
-        else {
-            $app->rebuild(
-                BlogID     => $obj->blog_id,
-                TemplateID => $obj->id,
-                NoStatic   => 1,
-            ) or return $app->publish_error();
+        if ( my $blog = $app->blog ) {
+            require MT::CMS::Blog;
+            my ( $path, $url );
+            if ( $obj->type eq 'index' ) {
+                $path = $blog->site_path;
+                $url = $blog->site_url;
+            }
+            else {
+                # must be archive since other types can't be dynamic
+                if ( $path = $blog->archive_path ) {
+                    $url = $blog->archive_url;
+                }
+                else {
+                    $path = $blog->site_path;
+                    $url = $blog->site_url;
+                }
+            }
+            # specific arguments so not to overwrite mtview and htaccess
+            MT::CMS::Blog::prepare_dynamic_publishing(
+                $eh, 
+                $blog,
+                undef,
+                undef,
+                $path,
+                $url
+            );
         }
     }
Index: /branches/release-36/lib/MT/CMS/Blog.pm
===================================================================
--- /branches/release-36/lib/MT/CMS/Blog.pm (revision 2026)
+++ /branches/release-36/lib/MT/CMS/Blog.pm (revision 2051)
@@ -2168,7 +2168,4 @@
       && ( -f $htaccess_path )
       && ( -f $mtview_path );
-    return 1 
-        if 'all' ne $blog->custom_dynamic_templates
-        && 'archives' ne $blog->custom_dynamic_templates;
 
     # IIS itself does not handle .htaccess,
Index: /branches/release-36/lib/MT/WeblogPublisher.pm
===================================================================
--- /branches/release-36/lib/MT/WeblogPublisher.pm (revision 2023)
+++ /branches/release-36/lib/MT/WeblogPublisher.pm (revision 2051)
@@ -1009,5 +1009,8 @@
     # we move the file that might be there so that the custom
     # 404 will be triggered.
-    if ( $tmpl->build_dynamic ) {
+    require MT::PublishOption;
+    if ( $tmpl->build_dynamic
+      || ( $map->build_type == MT::PublishOption::DYNAMIC() ) )
+    {
         rename(
             $finfo->file_path,    # is this just $file ?
@@ -1022,5 +1025,6 @@
     }
 
-    return 1 if ( $tmpl->build_dynamic );
+    return 1 if ( $tmpl->build_dynamic )
+        || ( $map->build_type == MT::PublishOption::DYNAMIC() );
     return 1 if ( $entry && $entry->status != MT::Entry::RELEASE() );
     return 1 unless ( $tmpl->build_type );
