diff --git a/app/components/spina/pages/new_page_button_component.html.erb b/app/components/spina/pages/new_page_button_component.html.erb
new file mode 100644
index 000000000..c2622d40f
--- /dev/null
+++ b/app/components/spina/pages/new_page_button_component.html.erb
@@ -0,0 +1,32 @@
+<% if view_templates.many? %>
+
+ <%= render Spina::UserInterface::DropdownComponent.new do |dropdown| %>
+ <% dropdown.button(classes: "btn btn-primary w-full") do %>
+ <%= helpers.heroicon("plus", style: :solid, class: "w-7 h-7 -ml-2") %>
+ <%=t 'spina.pages.new' %>
+ <% end %>
+
+ <% dropdown.menu do %>
+ <% view_templates.each do |template| %>
+ <%= link_to helpers.spina.new_admin_page_path(view_template: template.name, resource_id: @resource&.id), class: "block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900", data: {turbo_frame: "modal", action: "reveal#hide"} do %>
+
+ <%= template.title %>
+
+ <% if template.recommended %>
+ <%=t 'spina.pages.recommended' %>
+ <% end %>
+
+ <%= template.description %>
+ <% end %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+<% else %>
+
+ <%= link_to helpers.spina.new_admin_page_path(view_template: view_template.name, resource_id: resource&.id), class: "btn btn-primary w-full", data: {turbo_frame: "modal"} do %>
+ <%= helpers.heroicon("plus", style: :solid, class: "w-7 h-7 -ml-2") %>
+ <%=t 'spina.pages.new' %>
+ <% end %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/components/spina/pages/new_page_button_component.rb b/app/components/spina/pages/new_page_button_component.rb
new file mode 100644
index 000000000..292c0943f
--- /dev/null
+++ b/app/components/spina/pages/new_page_button_component.rb
@@ -0,0 +1,19 @@
+module Spina::Pages
+ class NewPageButtonComponent < Spina::ApplicationComponent
+ attr_reader :view_templates, :resource
+
+ def initialize(view_templates = [], resource: nil)
+ @view_templates = view_templates
+ @resource = resource
+ end
+
+ def view_template
+ view_templates.first
+ end
+
+ def render?
+ view_templates.any?
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/spina/admin/pages_controller.rb b/app/controllers/spina/admin/pages_controller.rb
index 675f8663a..8155b1017 100644
--- a/app/controllers/spina/admin/pages_controller.rb
+++ b/app/controllers/spina/admin/pages_controller.rb
@@ -8,10 +8,9 @@ class PagesController < AdminController
def index
add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
-
if params[:resource_id]
@resource = Resource.find(params[:resource_id])
- @page_templates = Spina::Current.theme.new_page_templates(recommended: @resource.view_template)
+ @page_templates = Spina::Current.theme.new_page_templates(resource: @resource)
@pages = @resource.pages.active.roots.includes(:translations)
else
@pages = Page.active.sorted.roots.main.includes(:translations)
diff --git a/app/views/spina/admin/pages/edit_template.html.erb b/app/views/spina/admin/pages/edit_template.html.erb
index 7acc10401..c3f7fa66b 100644
--- a/app/views/spina/admin/pages/edit_template.html.erb
+++ b/app/views/spina/admin/pages/edit_template.html.erb
@@ -15,7 +15,7 @@
<%= Spina::Page.human_attribute_name :view_template %>
- <%= f.select :view_template, options_for_select(current_theme.view_templates.map { |template| [template[:title], template[:name], {'data-page-parts' => template[:page_parts]}] }, @page.view_template), {}, class: "mt-1 form-select w-full" %>
+ <%= f.select :view_template, current_theme.new_page_templates(resource: @page.resource).map{ |template| [template.title, template.name] }, {}, class: "mt-1 form-select w-full" %>
diff --git a/app/views/spina/admin/pages/index.html.erb b/app/views/spina/admin/pages/index.html.erb
index 9bec51c31..10960e0c5 100644
--- a/app/views/spina/admin/pages/index.html.erb
+++ b/app/views/spina/admin/pages/index.html.erb
@@ -8,27 +8,7 @@
<% end %>
- <%= render Spina::UserInterface::DropdownComponent.new do |dropdown| %>
- <% dropdown.button(classes: "btn btn-primary w-full") do %>
- <%= heroicon("plus", style: :solid, class: "w-7 h-7 -ml-2") %>
- <%=t 'spina.pages.new' %>
- <% end %>
-
- <% dropdown.menu do %>
- <% @page_templates.each do |template| %>
- <%= link_to spina.new_admin_page_path(view_template: template.name, resource_id: @resource&.id), class: "block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900", data: {turbo_frame: "modal", action: "reveal#hide"} do %>
-
- <%= template.title %>
-
- <% if template.recommended %>
- <%=t 'spina.pages.recommended' %>
- <% end %>
-
-
<%= template.description %>
- <% end %>
- <% end %>
- <% end %>
- <% end %>
+ <%= render Spina::Pages::NewPageButtonComponent.new(@page_templates, resource: @resource) %>
<% end %>
diff --git a/lib/generators/spina/templates/config/initializers/themes/demo.rb b/lib/generators/spina/templates/config/initializers/themes/demo.rb
index a3421e6f7..d04e3ac51 100644
--- a/lib/generators/spina/templates/config/initializers/themes/demo.rb
+++ b/lib/generators/spina/templates/config/initializers/themes/demo.rb
@@ -37,7 +37,7 @@
theme.view_templates = [
{name: 'homepage', title: 'Homepage', parts: %w(headline body image_collection)},
{name: 'show', title: 'Default', parts: %w(body image repeater)},
- {name: 'demo', title: 'Demo', parts: %w(body image_collection image repeater)}
+ {name: 'demo', title: 'Demo', parts: %w(body image_collection image repeater), exclude_from: %w(articles)}
]
# Custom pages
diff --git a/lib/spina/theme.rb b/lib/spina/theme.rb
index 0128c8933..70035a93c 100644
--- a/lib/spina/theme.rb
+++ b/lib/spina/theme.rb
@@ -36,15 +36,17 @@ def initialize
@public_theme = false
end
- def new_page_templates(recommended: "")
+ def new_page_templates(resource: nil)
+ page_collection = resource&.name || "main"
@view_templates.map do |view_template|
next if is_custom_undeletable_page?(view_template[:name])
+ next if view_template[:exclude_from]&.include?(page_collection)
OpenStruct.new({
name: view_template[:name],
title: view_template[:title],
description: view_template[:description],
- recommended: view_template[:name] == recommended
+ recommended: view_template[:name] == resource&.view_template
})
end.compact.sort_by do |page_template|
[page_template.recommended ? 0 : 1]
diff --git a/test/dummy/config/initializers/themes/demo.rb b/test/dummy/config/initializers/themes/demo.rb
index b8e55ca16..3d2e2faa0 100644
--- a/test/dummy/config/initializers/themes/demo.rb
+++ b/test/dummy/config/initializers/themes/demo.rb
@@ -75,12 +75,14 @@
name: 'demo',
title: 'Demo',
description: 'Example including all parts',
- parts: ['repeater', 'repeater2', 'attachment', 'option', 'body', 'image_collection', 'image', 'portrait', 'landscape', 'wide']
+ parts: ['repeater', 'repeater2', 'attachment', 'option', 'body', 'image_collection', 'image', 'portrait', 'landscape', 'wide'],
+ exclude_from: %w(guides)
}, {
name: 'blogpost',
title: "Blogpost",
description: 'Article template',
- parts: ['body']
+ parts: ['body'],
+ exclude_from: %w(main)
}]
theme.custom_pages = [{