Tuesday, July 28, 2015

Tired of hiding the chrome on your content editor web part?

The situation: I'm lazy efficient.

The problem: When building a web part page, it gets very tiresome to always have to go into web part properties and change the Chrome to "None" so that the title and border don't show when I just want to publish web content.  I wish I could change the default option for all web parts to no chrome, because honestly, I'm usually creating my own content editor web parts to make the headings pretty anyway.

The solution: Create a new custom web part for your site which has the chrome already set to None.  Each new instance of the web part will be ready to go, so you won't have to edit the web part properties every. single. time.

Access level: To do this the recommended way, you should be a site owner for the site collection.
  1. Go to a your web part page. Click Add a Web Part (in any zone, it doesn't matter).  Select Media and Content > Content Editor.  Click the Add button.


  2. Click on the drop-down arrow on the right side of your web part title, and select Edit Web Part.

  3. In your Content Editor web part properties, expand the Appearance section, and change the Chrome Type to None.  Click the OK button to save your changes.


    Ahh! The chrome is still there!  Don't worry, you'll always see the chrome in Edit mode. Once you save the page, it will be hidden.


  4. Now you're going to export the web part you just created by clicking on the drop-down arrow next to the web part title, and selecting Export.
  5. You might get the following pop-up - click on OK twice.


  6. You should now get a prompt to save your .dwp web part file.  Save it and remember where you put it.


  7. Navigate to the Site Settings for your site collection.  (Gear icon in upper right > Site Settings.  If you're not at the top of the site collection, click on the link "Go to top level site settings" under Site Collection Administration.  If you don't have access there, request it or ask your site collection administrator to do this part for you.)

  8. Under the Web Designer Galleries section, click on Web Parts.  Click on the Files tab in the ribbon > Upload Document.  Browse to find the file you saved in step 6.  Click OK.

  9. Give your content editor web part a name and title that you'll remember (and that will distinguish it from the out-of-the-box Content Editor web part), and create a new category for your web part so that you can find it quickly. Click Save.



  10. Navigate back to your page.  Click on Add a Web Part in any zone.  Find the category you created in step 9, and click on the name of your web part.  Click the Add button.

  11. Add some content and Save your page.  You will see your content presented without the web part chrome. 
You will be able to use this custom web part throughout your site collection.  Take it a step further - if you have similar types of content that you add via content editor web parts, you can create additional custom content editors which give you a good starting point (and can help your other content contributors).

Friday, July 24, 2015

How to append the current site path to your search query

The situation: I had to add product and people search blocks to the search experience in my site collection.  Since the osssearchresults.aspx page cannot be edited, I created a new search results page.  I set the page query to only return results from my site collection. Once I had everything configured, a change request came in to only have results returned from the hierarchy where the search originated.

The problem: Since my search results page sat at the top of the site collection, I needed some way to pass the path where the search was performed to the results page.  I noticed that there was a parameter of u=[path] that seemed to appear frequently as I was navigating around my SharePoint sites, but I couldn't figure out how to append that to my URL as the search was sent.  I tried /.../Pages/Search-Results.aspx&u={lots_of_wrong_tokens}, but couldn't get anything to convert into the actual path.

The solution: After spending a lot of time researching with no luck, I noticed while editing the Search Box web part that there was an option to direct the queries to a Results Page URL of "~site/_layouts/15/osssearchresults.aspx?u={contexturl}" instead of sending to the search results web part on the page.  I appended "?u={contexturl} to the end of my search results page path on the Search Settings page, and like magic, that token converted into the path where the search originated.

I modified my Search Results web part query to "{searchboxquery} Path:{QueryString.u}", and my results page was only returning results from the hierarchy where the search was performed.

Possible issues: Visiting the search results page without a query used to return all results; now it shows no matches.  This isn't a huge deal, but not having the u=[path] in the URL leads to an empty search, and if there is a keyword parameter but no path, you see ye olde "something went wrong" message.



My failed searches: "send queries to custom results page URL", "sharepoint 2013 append something to search query", "sharepoint 2013 how to append something to the search query automatically", "sharepoint 2013 master page append text to search query" (yes, I was getting desperate!), "sharepoint 2013 using a custom search results page", "SharePoint 2013 how to edit osssearchresults.aspx", "SearchSmallInputBox", "add source to SharePoint 2013 search", "append path to search query URL", "SharePoint 2013 search default page add u=", "sharepoint 2013 search only this site", "SharePoint append path to search string", "sharepoint add path property to URL"