定制 pdaleramirez/super-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pdaleramirez/super-filter

Composer 安装命令:

composer require pdaleramirez/super-filter

包简介

A Craft CMS 5 plugin that lets you build your search page with search filters from your element fields and filter element entries by categories, tags, element relations and other fields.

README 文档

README

Build your search page with search filters from your element fields and filter element entries by categories, tags, element relations, products (Craft Commerce) and other fields. Easily setup your search page by using twig variable functions, back-end coding not needed. Supports Vue.js with pre-built styles.

Demo: super-filter-page Screenshot

Requirements

This plugin requires Craft CMS 4.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

    cd /path/to/project  
    
  2. Then tell Composer to load the plugin:

    composer require pdaleramirez/super-filter  
    
  3. In the Control Panel, go to Settings -> Plugins and click the “Install” button for Search Filter.

  4. Go to Super Filter -> Setting and click Install Example Data button to generate example entries (Optional).

Configuring Search Filter

  1. Create a new setup entry in the Setup Search tab and click on New Setup.
  2. Setup Config:
    • Title: Used for easy identification of your setup.
    • Handle: Necessary to initialize the search setup.
    • Items per page: The number of entries on the page during content load or pagination.
    • Base Template: If no template is found in the template override folder, it will fallback to pre-built base templates. There are only two options: Plain for traditional form reload and Vue for reactive form submission.
    • Watch Fields?: For Vue templates, this option watches the fields and filters items automatically.
    • Infinite Scroll?: For Vue templates, this option loads more items on scroll.
    • Template Override Folder: The folder containing the templates to override, modifying Vue or HTML files. The items.twig or items.vue must be copied to this folder to modify element attributes.
    • Element: The element type of the items or entries to be displayed.
    • Container: Section, group, or product type for an element.
    • Sort Fields: Drag fields to the selected column to be displayed on the sorting template for sorting elements.
    • Initial Sort: The default sort query on page load.
    • Search Fields: Drag fields to the selected column to be displayed on the search field template for filtering elements.

Using Super Filter

  1. To override a template or templates of the twig function from the selected base pre-built style templates. You can create the twig or vue file or open the super-filter plugin folder and copy a template or templates to the site template override folder path you specified on your configuration

styles

  1. Vue Base Template

    Use this twig function and pass handle.

    {{ craft.superFilter.render('handle') }}
    
    • fields.vue - displays the search filter fields html.
    • items.vue - displays the element entries or filtered element entries.
    • sorts.vue - displays the sorting field dropdown html.
    • main.vue - wrapper for fields and items.
    • fields/* - individual form input html.

    Plain Base Template

    Use super filter twig function to display search sections on your page. There are 5 twig function to be called on your page template.

    • craft.superFilter.setup('handle') - requires 1 parameter which is the handle of search set up entry. This should be the first function to be added to the template or the order of declaration should be above all other super filter twig function.

      • Template filename: setup.twig
    • craft.superFilter.displaySearchFields() - displays the search filter fields html.

      • Template filename: fields.twig and individual form input html in fields/* folder.
    • craft.superFilter.displaySortOptions() - displays the sorting field dropdown html.

      • Template filename: sorts.twig
    • craft.superFilter.items() - displays the element entries or filtered element entries.

      • Template filename: items.twig
    • craft.superFilter.getPaginateLinks() - displays element entries pagination or the infinite scroll trigger.

      • Template filename: pagination.twig
    • craft.superFilter.close() - needed to close the search page to reset templates path. So if you have included template after the super filter twig functions you will need this.

      The page template should look like this:

      <div id="search-app">
          {{ craft.superFilter.setup('searchList') }}
          <div class="row">
              <div class="col-sm-2 col-md-2">
                  {{ craft.superFilter.displaySearchFields() }}
              </div>
              <div class="col-sm-10 col-md-10">
                  {{ craft.superFilter.displaySortOptions() }}
                  {{ craft.superFilter.items() }}
                  {{ craft.superFilter.getPaginateLinks() }}
                  {{ craft.superFilter.close() }}
              </div>
          </div>
      </div>
      

Craft Commerce

If you are using craft commerce and don't want to return the default variants attribute on search results. You can add a super-filter.php setting file in the config folder with this value.

return [
  'variants' => false
];

Recommendation

Vue Base Template

  • It is recommended to initialize the calling of attributes and field attributes for your items or elements to optimize loading performance. Add the attributes or field handles on the second parameter of the setup twig variable E.g.
{{ craft.superFilter.render('superFilterShows', {
   attributes: ["title","superFilterGenre","dateCreated"]
}) }}

in your items.vue only the initialized attributes and field values are displayed. It will be called like this

{{ item.title }}
{{ item.superFilterGenre }}
{{ item.dateCreated }}

Customization

  • Pre-filter - If you want your items to load with pre defined filters you can pass a json key value pair in the craft.superFilter.setup twig function second parameter e.g.

Vue Base Template

        {{ craft.superFilter.render('superFilterShows', {
            filter: {
                superFilterImdbRating: 8,
                superFilterGenre: [4],
                superFilterShowTags: [7],
                superFilterShowTypes: "tv-series",
            }
        }) }}

Plain Base Template

{{ craft.superFilter.setup('searchList', {
    filter: {
       superFilterImdbRating: 8,
       superFilterGenre: [4],
       superFilterShowTags: [7],
       superFilterShowTypes: "tv-series",
    }
}) }}
  • Formatting Date attributes - The plugin supports https://day.js.org/ so you can easily format your date. In your items.vue you can call the date attribute like this:
{{ dayjs(item.dateCreated).format('dddd MMMM D, YYYY') }}
  • Item results modification - Call item event hook that allows you to modify the search and item results from an ajax results. E.g.
Event::on(SearchTypes::class, SearchTypes::EVENT_ITEM_ARRAY, function (ItemArrayEvent $event) {
    if (Craft::$app->getPlugins()->isPluginEnabled('commerce') == true
        && $event->searchType instanceof ProductSearchType) {
        $event->item['variants'] = $event->element->getVariants();
    }
});

Generate Console Command

Generate Example Data and Template Files

To generate example data with associated twig templates follow this steps:

  1. SSH to your server and run craft console command.
  2. Run the command php craft super-filter/generate/example. This will create example entries and create template files.
  3. After running command, visit your url https://your-url.test/super-filter-page you should be able to see Shows Entries Search Page.

Generate Setup Search Template Files

To generate initial items.vue template for a Setup Search:

  1. SSH to your server and run craft console command.
  2. Run the command php craft super-filter/generate/templates
  3. Enter a search setup handle: {theSetupSearchHandle}

Contact me for inquiries or if you require more customization. dalefirstpage@gmail.com

pdaleramirez/super-filter 适用场景与选型建议

pdaleramirez/super-filter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.36k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「craft-plugin」 「search filter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pdaleramirez/super-filter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pdaleramirez/super-filter 我们能提供哪些服务?
定制开发 / 二次开发

基于 pdaleramirez/super-filter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-19