【问题标题】:Spree custom landing page大礼包自定义登陆页面
【发布时间】:2015-07-01 14:56:26
【问题描述】:

我正在学习 Spree 商务并尝试使用 Deface 覆盖登录页面。 我需要覆盖的文件是: spree/frontend/app/views/spree/home/index.html.erb

    <% content_for :sidebar do %>
      <div data-hook="homepage_sidebar_navigation">
        <%= render :partial => 'spree/shared/taxonomies' %>
      </div>
    <% end %>

    <div data-hook="homepage_products">
      <% cache(cache_key_for_products) do %>
        <%= render :partial => 'spree/shared/products', :locals => { :products => @products } %>
      <% end %>
    </div>

我创建了一个部分: app/views/home/_landing.html.erb

我从 app/override/landing.rb 调用它,如下所示:

    Deface::Override.new(virtual_path: 'spree/home/index',
            replace: '[data-hook="homepage_products"]',
            name: 'landing-products',
            partial: 'home/landing')

    Deface::Override.new(virtual_path: 'spree/home/index',
            name: 'landing-sidebar',
            remove: '[data-hook="homepage_sidebar_navigation"]')

问题是它被插入到 spree/frontend/app/views/spree/layouts/spree_application.html.erb 在容器内>行>col-md-12 并且只希望它直接在导航栏之后和容器外部。 如何使用 Spree 最佳实践完全覆盖着陆(无需更改所有其他视图)?

    <!--[if lt IE 7 ]> <html class="ie ie6" lang="<%= I18n.locale %>"> <![endif]-->
    <!--[if IE 7 ]>    <html class="ie ie7" lang="<%= I18n.locale %>"> <![endif]-->
    <!--[if IE 8 ]>    <html class="ie ie8" lang="<%= I18n.locale %>"> <![endif]-->
    <!--[if IE 9 ]>    <html class="ie ie9" lang="<%= I18n.locale %>"> <![endif]-->
    <!--[if gt IE 9]><!--><html lang="<%= I18n.locale %>"><!--<![endif]-->
      <head data-hook="inside_head">
        <%= render partial: 'spree/shared/head' %>
      </head>
      <body class="<%= body_class %>" id="<%= @body_id || 'default' %>" data-hook="body">
        <%= render partial: 'spree/shared/google_analytics.js' %>
        <%= render partial: 'spree/shared/header' %>

        <div class="container">
          <div class="row" data-hook>
            <%= breadcrumbs(@taxon) %>

            <%= render partial: 'spree/shared/sidebar' if content_for? :sidebar %>

            <div id="content" class="<%= !content_for?(:sidebar) ? "col-sm-12" : "col-sm-8 col-md-9" %>" data-hook>
              <%= flash_messages %>
              <%= yield %>
            </div>

            <%= yield :templates %>
          </div>
        </div>
      </body>
    </html>

【问题讨论】:

  • Deface 是一种巨大的反模式,我在应用程序的所有前端部分都避免使用它(但仍将它用于后端页面)。除非你有一个非常简单的应用程序,否则我建议不要破坏。

标签: ruby-on-rails spree deface


【解决方案1】:

方法是创建一个新文件app/views/layout/landing.html.erb

并覆盖 HomeController
app/controllers/spree/home_controller_decorator.rb

 module Spree
    class HomeController < Spree::StoreController

      layout 'landing'

      helper 'spree/products'
      respond_to :html

      def index
        @searcher = build_searcher(params.merge(include_images: true))
        @products = @searcher.retrieve_products
        @taxonomies = Spree::Taxonomy.includes(root: :children)
      end
    end
  end

【讨论】:

  • 是的,这完全可以接受,但请注意,您可以在 Spree 配置设置中设置 Spree 布局。 (我认为 Spree::Config[:default_layout] 或类似的东西)。如果您在配置设置中全局更改它,您的自定义布局将应用于所有控制器,这比在控制器中明确指定布局更干燥。但是您的解决方案非常适合进行设置。
  • 感谢您的回答@JasonFB
猜你喜欢
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 2012-12-13
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多