We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52499
    • 6 Posts
    Hi, I have a searchbar on a blog page and what I would like is when the searchbar is used that I am able to know this so I can remove the getResources that is pulling All of the posts.
    What is happening is that the search is being ran just fine but the results are being appended onto the end of the rest of the posts.
    I would like to remove the getResources bit when the searchbar is used, how is this possible?.


    Bellow is the getResources that retrieves all the posts:
                 [[!getResources? 
                               &parents=`8`
                               &depth=`1`
                               &limit=`9`
                               &tpl=`post.right`
                               &tplOdd =`post.left`
                               &includeTVs=`1`
                               &processTVs=`1`
                               &sortby=`menuindex`
                               &sortdir=`ASC`
                           ]]
    


    And here is the code that outputs the search results:
    [[!SimpleSearch?
                    &ids=`8`
                    &highlightResults=`1`
                    &highlightClass=`sisea-highlight`
                    &includeTVs=`1`
                    &perPage=`6`
                    &containerTpl=`search-results-container`
                    &noResultsTpl=`search-no-results`
                    &tpl=`layout.search.result.row`
                    &maxWords=`7`
              ]]
    


    I have looked into "IF" addon but I do not know what to put in as the check to see if the search is being used



    Thanks very much in advance



    Regards,

    Ryan smiley
      • 17301
      • 932 Posts
      Assuming I understand correctly you'll need to create a new resource for the search results and put the "[[!SimpleSearch]]" with your parameters into the context and publish it.

      Then on the search form you'll need to add in &landing=`` ie:
      [[!SimpleSearchForm? &landing=`199` &tpl=`searchTpl`]]
      Except where I've put 199 will be the resource ID of the search results page you just created.

        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 52499
        • 6 Posts
        Quote from: lkfranklin at Jul 12, 2016, 10:58 AM
        Assuming I understand correctly you'll need to create a new resource for the search results and put the "[[!SimpleSearch]]" with your parameters into the context and publish it.

        Then on the search form you'll need to add in &landing=`` ie:
        [[!SimpleSearchForm? &landing=`199` &tpl=`searchTpl`]]
        Except where I've put 199 will be the resource ID of the search results page you just created.


        Thanks for the quick response LK.

        Wont this just put the search results on a different page?, the issue i'm having is when the search is competed the posts that are already there dont go away and leave only the seach results on their own

        Here is a screenshot (sorry for zoomed out so much had to get everything is)

        it is taken after a search is completed, the search result is green

        Thanks
          • 3749
          • 24,544 Posts
          As LK suggests, one common method is for the Search Bar to be a form where the action is some other page. A snippet on the other page actually does the search based on the criteria sent from the form and posts its results on the same page with the snippet tag.

          You could put a div around the getResources tag and hide that div with JavaScript if there are search results, but I think using another page for the results would be much easier.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 52499
            • 6 Posts
            Quote from: BobRay at Jul 12, 2016, 05:23 PM
            As LK suggests, one common method is for the Search Bar to be a form where the action is some other page. A snippet on the other page actually does the search based on the criteria sent from the form and posts its results on the same page with the snippet tag.

            You could put a div around the getResources tag and hide that div with JavaScript if there are search results, but I think using another page for the results would be much easier.

            Thanks for getting back to me BObRay,

            I need to display the results on the same page unfortunately, I was trying to stay away from the javascript route as I know it can be done in modx because another site I have access to it was done, I will add that code in bellow hopefully it will make sense to you.

            	<!-- SUBHEADER -->
            	<div class="subheader subheader--search" style="background-image: url('assets/components/layout/images/subheader-knowledge.jpg'); background-position: right top">
            		<div class="container">
            			<h1 class="subheader__title subheader__title--lg text-center"><small>our sports & science</small> Knowledge</h1>
            		</div>
            		<!-- SEARCH -->
            		<div class="search">
                        [[$knowledge.nav]]  
            		</div>
            		<!-- /SEARCH -->
            	</div>
            	<!-- / SUBHEADER -->
            
            	<!-- CONTENT -->
                [[!If?
                   &subject=`[[!#get.search:stripTags]]`
                   &operator=`empty`
                   &then=`
                    	<section class="section--white">
                    		<div class="container container--xl container--flat results">
                        		[[!getResourcesTag? 
                    		        &parents=`5` 
                    		        &tagRequestParam=`tag` 
                    		        &tagKey=`[[!#get.type:stripTags:is=`sport`:then=`knowledge.tag.sport`:else=`knowledge.tag.subject`]]` 
                    		        &tpl=`knowledge.item` 
                    		        &includeTVs=`1` 
                    		        &processTVs=`1` 
                    		        &tvPrefix=`` 
                    		        &limit=`[[!#get.limit:stripTags:default=`8`]]` 
                    		        &sortbyTV=`knowledge.item.date` 
                    		    ]]
                    		</div>
                    	</section>
            		    [[!getResourcesTag? 
            		        &parents=`5` 
            		        &tagRequestParam=`tag` 
            		        &tagKey=`[[!#get.type:stripTags:is=`sport`:then=`knowledge.tag.sport`:else=`knowledge.tag.subject`]]` 
                            &tpl=`layout.total.results` 
            		        &includeTVs=`1` 
            		        &processTVs=`1` 
            		        &tvPrefix=`` 
            		        &limit=`1` 
            		        &sortbyTV=`knowledge.item.date` 
            		    ]]                 
                        <div class="load-more">
                            <div class="container">
                                <a id="loadmorelink" style="display: none;" href="[[~[[*id]]]][[!#get.type:stripTags]]/[[!#get.tag:stripTags]][[!#get.key:stripTags:is=`knowledge.tag.subject`:then=`&key=knowledge.tag.subject`:else=``]]#!" class="link-block">
                                    Read more posts
                                    <span><i class="fa fa-angle-down"></i></span>
                                </a>
                            </div>
                        </div> 	
                        <div class="animation_image" style="display:none;"><img src="assets/components/layout/images/ajax_loading.png"> Loading...</div>
                   `
                   &else=`[[!SimpleSearch? &ids=`5` &tpl=`layout.search.result.row` &containerTpl=`layout.search.result.container` &highlightClass=`blue_sq` &noResultsTpl=`layout.search.result.empty`]]`
                ]]
            	<!-- / CONTENT -->


            regards,
            Ryan
              • 3749
              • 24,544 Posts
              I suspect that your &subject line is never truly empty.

              I would be inclined to try a custom snippet that called SimpleSearch with $modx->runSnippet() if a form has been submitted and returned the results, and that other stuff (maybe with $modx->getChunk() ) if not.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting