최근 검색


최근 검색 없음

Restrict search bar

답변함


2023년 4월 03일에 게시됨

Is there a way to prevent users who aren't signed in from using the search function?


0

1

댓글 1개

image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Jack! You could use an if statement with the signed_in property to wrap around the search functionality. For example, if you are using the default Copenhagen theme and wanted to hide the search functionality on the home page, you would go to home_page.hbs and add {{#if signed_in}} on line 5 and then close that on line 12 with {{/if}}, like this (bolded portions are what I added):

<section id="main-content" class="section hero">
  <div class="hero-inner">
    {{#if signed_in}}
    <h2 class="visibility-hidden">{{ t 'search' }}</h2>
    <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" focusable="false" viewBox="0 0 12 12" class="search-icon" aria-hidden="true">
      <circle cx="4.5" cy="4.5" r="4" fill="none" stroke="currentColor"/>
      <path stroke="currentColor" stroke-linecap="round" d="M11 11L7.5 7.5"/>
    </svg>
    {{search submit=false instant=settings.instant_search class='search search-full'}}
    {{/if}}
  </div>
</section>

Note that you would need to do that in each template that you wanted to restrict, such as the category, section, and article templates. You could probably come up with a more elegant solution using JS, but I just wanted to give you the general functionality for accomplishing this!

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물