We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36805
    • 354 Posts
    Hi everyone,

    Some of my site documents are used only in ditto listings. These list items use their own template. If accessed directly by url they forward to their parent by using a snippet I wrote.

    They show up in AS results like normal pages which is fine. However they display their own pagetitle in the link text. I need to tweak AS to use their parent pagetitle instead.

    In the simplest case I think it would suffice if I'd have 2 extra placeholders [+as.parentpagetitle+] and [+as.templateid+]. I could use some fairly simple PHx logic to pick the correct pagetitle.

    Can anyone point me to the right place in the ajaxsearch code or help me out another way? Thanks in advance!

    PS: Using Evo 1.0.5. with AS 1.9.2 using non-ajax mode

    EDIT: Instead of hacking AS I wrote a snippet to tackle this

    $listItems = array(9,10,11);
    if (!isset($id) || !is_numeric($id))
    $doc = $modx->getDocument($id,'pagetitle,parent,id,template');
    $parent = $modx->getDocument($doc['parent'],'id,pagetitle');
    if ( !in_array( $doc['template'], $listItems) )
    return '<a href="' . $modx->makeUrl($doc['id']) . '">'.$doc['pagetitle'].'</a>';
    return '<a href="' . $modx->makeUrl($doc['id']) . '">'.$parent['pagetitle'].'</a>';

    Then in my result.tpl.html
    <div class="[+as.resultClass+]">
      [[getSearchResLink? &id=`[+as.id+]`]]
      <span class="[+as.descriptionClass+]">[+as.description+]</span>
      <div class="[+as.extractClass+]"><p>[+as.extract+]</p></div>
      <span class="[+as.breadcrumbsClass+]">[+as.breadcrumbs+]</span>
    [ed. note: dorstox last edited this post 12 years, 7 months ago.]