Buglet in simplesearch_item.html.twig?

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


to



{% if page.header.link %}

{{ page.title }}


{% else %}

{{ page.title }}


{% endif %}

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

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

‘’’

{% 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 }}


’’'

Designed to handle

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

{% 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:

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

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.

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.

Does this work?

<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>

Yes! You got it. Much better!