I’m building a blog and I’ve added a simple search plugin.
As for a example I’ve taken a skeleton with search and blog modules.
Let’s assume, that my blog has this URL - /blog
blog.html.twig uses standard URL expressions based on other examples:
{% embed 'partials/base.html.twig' %}
{% set collection = page.collection() %}
{% set base_url = page.url %}
{% if base_url == '/' %}
{% set base_url = '' %}
{% endif %}
{% block content %}
{{ page.content }}
<section class="container-fluid">
<div class="row">
<div class="col-md-8">
{% for child in collection %}
{% include 'partials/blog_item.html.twig' with {'page':child, 'truncate':true} %}
{% endfor %}
</div>
{% include 'partials/blog_sidebar_footer.html.twig' %}
</div>
</section>
{% if config.plugins.pagination.enabled and collection.params.pagination %}
{#% include 'pagination.html.twig' with {'pagination':collection.params.pagination} %#}
{% include 'pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
{% endif %}
{% endblock %}
{% endembed %}
blog_sidebar_footer.html.twig is a simple wrapper:
<div class="col-md-4" id="side-bar">
{% include 'partials/sidebar.html.twig' %}
</div>
And sidebar.html.twig:
{% for module in page.collection({'items':{'@taxonomy.category': 'sidebar'},'order': {'by': 'default', 'dir': 'asc'}}) %}
{% if module.template %}
{% if module.header.surround %}
{% include 'sidebar/' ~ module.template ~ '.html.twig' %}
{% endif %}
{% endif %}
{% endfor %}
<div class="sidebar section" id="sidebar">
{% for module in page.collection({'items':{'@taxonomy.category': 'sidebar'},'order': {'by': 'default', 'dir': 'asc'}}) %}
{% if module.template %}
{% if not module.header.surround %}
{% include 'sidebar/' ~ module.template ~ '.html.twig' %}
{% endif %}
{% endif %}
{% endfor %}
{% if config.plugins.simplesearch.enabled %}
<div class="widget HTML">
<h2 class="title">Search</h2>
<div class="widget-content simplesearch">
{% include 'partials/simplesearch_searchbox.html.twig' %}
</div>
</div>
{% endif %}
</div>
So, once I enter some data in search box I get Error 404
The full URL looks like: https://localhost/grav-blog/blog/search/query:test
Exploring examples I assume, that URL should be without /blog/ slug -> https://localhost/grav-blog/search/query:test
Once I enter URL manually https://localhost/grav-blog/search/ I see Search Results page, but if I add a query -> array_replace_recursive(): Expected parameter 2 to be an array, string given
What I’m missing? I already tried overwriting all templates with the ones from demo skeletons - but I had no luck…
The route is route: /search
If I make route: /blog/search the search result’s URL will look like: https://localhost/grav-blog/blog/blog/search/query:test
I’ve downloaded a Pin Press Blog skeleton as for example and copied the template overrides with twig part.
These variables from blog.html.twig outputs different results:
{% set base_url = page.url %}
Once I run example on localhost and output
{{ base_url }}
{{ page.url }}
I get /grav_blog and /grav_blog paths.
Once I run it from mine project I get: /grav-blog/blog and /grav-blog/blog
The main difference is that on mine project I’ve been using Gantry5 framework for template part, if it make any difference. Don’t know why the {{ base_url }} and {{ page.url }} are changed… I’ve already tried to fully overwrite mine templates with templates from example, as for a try, but it acts the same…
System settings (system/config/system/yaml) are untouched:
update
I don’t know why, but changing the {% set base_url = page.url %} in blog.html.twig to {% set base_url = page.parent.url %} resolves the issue on a blog items list page. I don’t know - is it correct…
The problem still persist on item.html.twig page where base_url settings are the same:
{% set base_url = page.parent.url %}
{% if base_url == '/' %}
{% set base_url = '' %}
{% endif %}
But with this configuration, clicking on a last pagination page, brings me to a search result page instead of page:3… Also in doesn’t give me a right base url in a blog item page
I meant, if you change a home page from a blog to other one this bug should appear.
I’ve found a old forum thread with something similar, still examining it
@pamtbaau the quickest way to reproduce is to download a skeleton with prepended data and blog template. Because every blog template has base_url settings (set base_url).
Yes, with your provided script everything works fine.
It seems, that you are right, that the problem is in a old template.
I will compare all the twig logic in templates