Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Buglet in simplesearch_item.html.twig?

Started by Norma White 6 years ago · 7 replies · 512 views
6 years ago

One of my pages inside blog has a page.header.link - a link to a special page that is not within blog (because it is modular with a header and sidebar. This works correctly when the page header in the list of pages is selected.

However, if the special page is found from the search box, the link fails.

I have fixed this on my site with a minor change to simplesearch_item.html.twig

Expanding
<div class="search-item">
<div class="search-title">
<h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
</div>

to
<div class="search-item">
<div class="search-title">
{% if page.header.link %}
<h3><a href="{{base_url}}/{{ page.header.link }}">{{ page.title }}
</a></h3>
{% else %}
<h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
{% endif %}
</div>

There may be more elegant ways, but this works for me.

6 years ago

Please check the code you showed. Also please enclose code in triple single ticks (```).

last edited 08/16/20 by pamtbaau
6 years ago

‘''<section class="search-row">

{% set banner = page.media.images|first %}

{% if banner %}
<div class="search-image">
<a href="{{ page.url }}">{{ banner.cropZoom(100,100).html|raw }}</a>
</div>
{% endif %}
<div class="search-item">
<div class="search-title">
{% if page.header.link %}
<h3><a href="{{base_url}}/{{ page.header.link }}">{{ page.title }}</a></h3>
{% else %}
<h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
{% endif %}
</div>

<div class="search-details">
<span class="search-date">{{ page.date|date(config.system.pages.dateformat.short) }}</span>
</div>

<p>{{ page.summary|raw }}</p>

<hr/>
</div>
</section>’’'

Designed to handle

6 years ago

I meant wrapping your code in triple backticks (```), so it shows as:

TWIG
{% set banner = page.media.images|first %}

{% if banner %}
    {{ banner.cropZoom(100,100).html|raw }}
{% endif %}

{% if [page.header.link](http://page.header.link) %}
    {{ page.title }}
{% else %}
    {{ page.title }}
{% endif %}

{{ page.date|date(config.system.pages.dateformat.short) }}
{{ page.summary|raw }}

Are you sure this is the code that works for you?

Perhaps the second if -then should be:

TWIG
{% if page.header.link is defined %}
    <a href="{{ page.header.link }}">{{ page.title }}</a>
{% else %}
    {{ page.title }}
{% endif %}
6 years ago

My apologies, I do not understand the interface between me and the forum. The code that shows looks bizarre and is not at all what I have. Sorry for the confusion.

In simplesearch_item.html.twig, I am simply replacing the page.url href with the url that is specified in the page.header.link of the found page. My idea is that the teaser in the short list should behave the same way as it does in the (sidebar) full teaser list and indeed the same way as in the list for a selected tag.

I can find no way to put code into the forum ''' did not help. So the intent is a simple if ... else ...endif.
In the case where there is a page.header.link defined, the link to the item to be displayed is
base_url cat / cat page.header.link
and not page.url which is links to the teaser.

An alternative might be to include title.html.twig but not sure about the formatting.

If you are looking at my site nhbpeterborough.com, choose archives, then pick Bands from the popular tags. Summit Terrace is there, click on it and you arrive at a modular page full of information. but if you Search for summit, the link on the next page takes you only to a teaser link. With my new code, it goes straight to the full modular page.

6 years ago

I tried and it mangled the code - looked nothing like the code I pasted in. So I hope I was able to convey the small change in words.

6 years ago

Does this work?

TWIG
<div class="search-item">
        <div class="search-title">
           {% if page.header.link %}
              <h3><a href="{{base_url}}/{{ page.header.link }}">{{ page.title }}</a></h3>
           {% else %}
              <h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
           {% endif %}
        </div>

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago