Search

Hi everyone,

I am using the Search Index and Sitemap extensions by Nick Dunn. Great extensions Nick!

Everything is working fine but I'm missing page links when a search returns a hit for a page. I have about 150 pages with multiple subcategories.

I have come so far that the full link path for a page is returned when forcing the ID. My problem is that the entry ID is not passed to the if statement.

<xsl:if test="@id = $search-entry-id">

The full code:

<xsl:import href="truncate.xsl"/>

<xsl:template match="search/entry">
    <xsl:variable name="search-entry-id" select="./@id"/>
    <xsl:variable name="search-entry-section" select="./@section"/>
    <xsl:variable name="search-entry-score" select="./@score"/>

    <div id="search">
        <xsl:choose>
            <xsl:when test="$search-entry-section = 'staff'">
                <h3>
                    <xsl:value-of select="/data/search-staff/entry[@id = $search-entry-id]/title/item"/>&#160;<xsl:value-of select="/data/search-staff/entry[@id = $search-entry-id]/surname"/>,
                    <xsl:value-of select="/data/search-staff/entry[@id = $search-entry-id]/first-name"/>
                </h3>
                <xsl:choose>
                    <xsl:when test="image/filename != ''">
                        <img src="{$workspace}/images/staff/{$image}" width="100" height="120" alt="" />
                    </xsl:when>
                    <xsl:otherwise>
                        <img src="{$workspace}/images/staff.gif" width="100" height="120" alt="" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$search-entry-section = 'pages'">
                <h3>
                    <xsl:copy-of select="/data/search-pages/entry[@id = $search-entry-id]/page-name/page"/>
                </h3>
                <xsl:call-template name="truncate">
                    <xsl:with-param name="node" select="/data/search-pages/entry[@id = $search-entry-id]/content"/>
                    <xsl:with-param name="limit" select="'300'"/>
                </xsl:call-template>

                <xsl:apply-templates select="/data/navigation/page[not(types/type = 'hidden') and not(types/type = 'admin')]" mode="page-link">
                    <xsl:with-param name="search-entry-id" select="$search-entry-id"/>
                </xsl:apply-templates>

            </xsl:when>
        </xsl:choose>
    </div>
</xsl:template>

<xsl:template match="page" mode="page-link">
    <xsl:param name="search-entry-id"/>
    <xsl:if test="@id = $search-entry-id">
        <xsl:value-of select="$root"/>
        <xsl:for-each select="ancestor::page | current()">
        <xsl:value-of select="concat(@handle,'/')"/>
        </xsl:for-each>
    </xsl:if>
    <xsl:apply-templates select="page[not(types/type = 'hidden') and not(types/type = 'admin')]" mode="page-link"/>
</xsl:template>

I think that when you make the recursive call to your page template you need to pass the search-entry-id parameter.

Thanks wisolman, I found out that the id numbers I compared was not the same. o.O

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details