能否将搜索表单放在我们404页面的顶部?

似乎 404 页面没有插件插槽,并且根据 https://meta.discourse.org/t/how-to-add-custom-js-code-to-the-404-pages/165214,您必须使用纯 JS。

尝试在主题组件的 Body 选项卡中添加类似以下内容:

<script type="text/javascript">
    var x = document.getElementsByClassName("page-not-found");
    var search = '<div class="page-not-found-search-top"><h2>Search this site</h2><p></p><form action="/search" id="discourse-search"><input type="text" name="q" value=""><button class="btn btn-primary">Search</button></form><p></p></div>'
    x.item(0).innerHTML += search
</script>

您可能需要对 CSS 进行一些调整,尝试:

.page-not-found-search {
    display: none;
}

.page-not-found-search-top button {
    margin-left: 10px;
}

.page-not-found-search-top input {
    width: 600px;
}

希望这有帮助!

8 个赞