2

I have a Low:Search result that is a child entry in a relationship, for which I wish to point at it's parent entry.

The child doesn't have its own URL that resolves, it just resides within its parent index. The entries in the other collection have URLs that resolve.

I tried to redirect from the child URL to its parent. No luck, perhaps a parse order issue?

I also tried to set the inner html - that displays the content - based on a conditional within the {low_search:results} tag, using 'collection_name', but it also isn't working. I receive a message that the page cannot be properly displayed.

The only way I can get it to work is if I have 2 duplicate {low_search:results} tags, targeting each collection separately, as per Group Low Search results by channel/collection?, but I get both a result set and a 'Sorry, no results' message as both tags are firing, but the keywords are not in both collections.

I must be missing something obvious, as relationships have been around a long time in EE.

Can anyone with a clear head see what I'm missing?

Thanks very much for reading.


Code example - I don't expect this to work as is, but this structure is what I was hoping would work...

  {exp:low_search:results query="{segment_3}" limit="10"}

  {if count == 1}
    {if low_search_keywords}<p>Term searched for: <strong>{low_search_keywords}</strong>.</p>{/if}
    <p>Total results: <strong>{absolute_results}</strong>.</p>
  {/if}

  {if channel == "members"} {!-- child of 'bands' --}

  <div class="entry" style="clear: both;">
    <h3><a href="/band-members">{title}</a></h3>
    <p>{low_search_excerpt}</p>
  </div>

  {/if}

  {if channel == "musicians"} {!-- no children --}

  <div class="entry" style="clear: both;">
    <h3><a href="{page_url}">{title}</a></h3>
    <p>{low_search_excerpt}</p>
  </div>

  {/if}

  {paginate}
    <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
  {/paginate}

  {if low_search_no_results}
    <p>Sorry, your query did not return any results. Check your spelling or try a different search term.</p>
  {/if}

{/exp:low_search:results}

Working code:

{if channel_short_name == "members"}

<div class="entry">
{parents field="cf-members_item"}
  <h3><a href="{parents:page_url}">{title}</a></h3>
{/parents}
  <p>{low_search_excerpt}</p>
 </div>

{if:else}

<div class="entry">
  <h3><a href="{page_url}">{title}</a></h3>
  <p>{low_search_excerpt}</p>
</div>

{/if}
1
  • Can you post some template code
    – CreateSean
    Commented Jun 1, 2015 at 21:11

2 Answers 2

2

Really we need to see your template code as it's not really clear what you're doing/trying.

However would it not be a case of using an embed or channel entries loop within the search results? Thats what you want right, to display the parent of an entry within search results, if that result is a child entry 'type' or channel??

Something like this, written on the fly so probably doesn't work but hopefully give you the idea of what I'm getting at:

{exp:low_search:results 
   orderby_sort="title|asc"
   query="{segment_3}"  
}
    {!-- Detect entries of type child --}
    {if channel_short_name == 'child_channel'}

        {!-- get the parent entry
        {parents field="relationship_field"}
                {exp:channel:entries entry_id="{parents:entry_id}" dynamic="no"}

                    {!-- Display Parent Stuff --}
                    {url_title_path='parent_channel/display'}

                {exp:channel:entries}
        {/parents}

{/exp:low_search:results}

Or have I missed your point?


Edit 1

Since code example, I've written a more consise answer for you. It's not clear if you wish to display the {title} of the parent or child so I've added alternatives to relect this. Also, I've utilised an embedded template to make the markup more readable, otherwise you'll end up with many EE tags inside the anchor tag!

Edit 2 : Following Low's comments I've used namespaced variables instead of the extra channel entries loop. I've had issues with parameters and EE tags inside relationship parent loops before (hence initial avoidence) so my code is supplied untested!

First the main template...

{if channel == "members"} {!-- child of 'bands' --}

  <div class="entry" style="clear: both;">

   {!-- This example assumes child's title --}
   <h3>
   {parents field="parents_relationship_fieldname"}
     <a href='{parents:url_title_path='templates/bands'}'>
   {/parents}
       {title}
     </a>
   </h3>
   <p>{low_search_excerpt}</p>

  </div>

 {/if}

If you wantedt he parent title, try something like this instead:

{if channel == "members"} {!-- child of 'bands' --}

  <div class="entry" style="clear: both;">

   {!-- This example assumes parent's title --}
   {parents field="parents_relationship_fieldname"}
     <h3><a href='{parents:url_title_path='templates/bands'}'>{parents:title}</a></h3>
   {/parents}
   <p>{low_search_excerpt}</p>

  </div>

 {/if}
5
  • Thanks #Blatant. I have added code to my OP. Will give your approach a go, but what I want to do is provide the parent's URL to the user when the result is a child. Look at the <h3> tags in my code to see the differences between the two.
    – dbigca
    Commented Jun 2, 2015 at 13:30
  • No problem, do mark the answer, whichever you tihnk is more correct, to help others in the network :)
    – Blatant
    Commented Jun 3, 2015 at 9:54
  • 1
    I wouldn't recommend using the channel:entries loop, as that can lead to parse order issues. The {url_title_path} and {title} variables will be parsed by the outer Results tag before the channel:entries can get to them. Using the prefixed var method (as per the native docs) is the preferred method.
    – Low
    Commented Jun 3, 2015 at 11:09
  • Low's comment is correct, this is why I origionally used embeds, its a poor man's way of breaking out of the parse order as embeds are always fashionably late, haha. I have edited again, not sure if url_title_path actually works within namespaced variables (hence why I avoid!) but any how...
    – Blatant
    Commented Jun 3, 2015 at 13:12
  • Thanks @Blatant. Your code, with Low's input, provided the necessary direction. Greatly appreciate your time and attention! I have updated my OP with the working code.
    – dbigca
    Commented Jun 4, 2015 at 2:27
3

@Blatant is on the right track, but the code example isn't optimal.

Since the Results tag builds upon the native exp:channel:entries tag, you're able to use the native Relationships Field options. So, to get to an entry's parent, use something like this:

{parents field="relationship_field"}
    {parents:url_title}
{/parents}

Use that to compose the URL you want for the channel you want.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.