<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by LinhDo</title><link href="https://world.optimizely.com/blogs/LinhDo/" /><updated>2010-11-17T07:53:47.1870000Z</updated><id>https://world.optimizely.com/blogs/LinhDo/</id><generator uri="https://world.optimizely.com/blogs/LinhDo/" version="2.0">Optimizely World</generator><entry><title>Add Google search box to CMS site using Dynamic content</title><link href="https://world.optimizely.com/blogs/LinhDo/Dates/2010/11/Add-Google-search-box-to-CMS-site-using-Dynamic-content/" /><id>https://world.optimizely.com/blogs/LinhDo/Dates/2010/11/Add-Google-search-box-to-CMS-site-using-Dynamic-content/</id><published>2010-11-17T06:46:00.0000000Z</published><updated>2010-11-17T07:53:47.1870000Z</updated><author><name>dobachlinh@gmail.com</name></author><category term="Blog post" /><summary type="html">&lt;p&gt;Developers all know how easy to add a Google search box to their website. But with me, it only get attractive when I verify an issue regarding to Dynamic Content, when I found that Dynamic Content is really nice feature. So I try to create my first Dynamic content with Google search box.&lt;/p&gt;  &lt;p&gt;This entry shows a sample to create your own custom search engine using Google Custom Search and Dynamic Content in CMS template pages.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;1. &lt;/b&gt;&lt;b&gt;Get Search Engine ID&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You should login to your Google Account first then go to &lt;a href="http://www.google.com/cse/"&gt;http://www.google.com/cse/&lt;/a&gt; to create your custom search engine. After that go to Control Panel link and get your Search engine unique ID. It looks like this &lt;font color="#f79646"&gt;&lt;i&gt;007791610224680591377:m3lgrymjnfy&lt;/i&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#f79646"&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;2. &lt;/b&gt;&lt;b&gt;Create GoogleSearch Dynamic Content&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I create settings for this Dynamic Content with a User Control to save search site. The settings interface looks like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="/link/ec1c7995a657490d9a909d506959e3da.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/link/3c5a6fac72204592987f7b74dd08ed30.png" width="370" height="131" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can input your site name for the second search-site option (the first one will be all sites).&lt;/p&gt;  &lt;p&gt;And one more user control to display the search box. Note that you have to put your key – that get from step 1 to &lt;font color="#0000ff"&gt;cx&lt;/font&gt; value here&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;asp&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;HiddenField&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;cx&amp;quot;&lt;/font&gt;&lt;/span&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;Value&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Put You Key Here&amp;quot;&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt; runat&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/font&gt;&lt;/span&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 10pt" color="#0000ff"&gt;/&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;cx&lt;/font&gt; = The identifier of the custom search engine.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;This code below is to show the result from Google (provide by Google custom search engine)&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;id&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;ResultArea&amp;quot;&amp;gt;&amp;lt;/&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 10pt" color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;script&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 10pt" color="#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; googleSearchIframeName = &lt;span&gt;&lt;font color="#a31515"&gt;&amp;quot;ResultArea&amp;quot;&lt;/font&gt;&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; googleSearchFrameborder = 0;&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; googleSearchDomain =&lt;span&gt;&lt;font color="#a31515"&gt;&amp;quot;www.google.com&amp;quot;&lt;/font&gt;&lt;/span&gt;;&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt; googleSearchPath =&lt;span&gt;&lt;font color="#a31515"&gt;&amp;quot;/cse&amp;quot;&lt;/font&gt;&lt;/span&gt;;&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;script&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;script&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/font&gt;&lt;/span&gt; &lt;span&gt;&lt;font color="#ff0000"&gt;src&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 10pt" color="#0000ff"&gt;=&amp;quot;http://www.google.com/afsonline/show_afs_search.js&amp;quot;&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here we go, &lt;strong&gt;Google search box in CMS site&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="/link/04b460c10f9749f39dfca1fb305649e6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/link/01a45dec8de8451796ac4153b86f0c33.png" width="385" height="329" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Download full source code here:&lt;/b&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:523d5096-b036-41e7-b3bd-2b25f6aa60db" class="wlWriterEditableSmartContent"&gt;&lt;p&gt; &lt;a href="/link/a17e3081c6f441e68fa915f2db217cce.zip" target="_blank"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:54afba3a-b24b-4fbe-bb4e-3bdc82ac09c1" class="wlWriterEditableSmartContent"&gt;&lt;p&gt; &lt;a href="/link/3def2530678a455d926fc8d4622c84dc.zip"&gt;DynamicContentSample.zip&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin-left: 0cm; margin-right: 0cm"&gt;&lt;font face="Times New Roman"&gt;&lt;span style="mso-ansi-language: en-us" lang="EN-US"&gt;&lt;font style="font-size: 12pt"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Unzip and copy all files to Templates/DynamicContent folder then register the control in episerver.config: &lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height: normal; list-style-type: disc; margin: 0cm 0cm 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Courier New"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 10pt"&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#a31515"&gt;add&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#ff0000"&gt;description&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;quot;&lt;span&gt;&lt;font color="#0000ff"&gt;Google Search&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#ff0000"&gt;name&lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;span&gt;&lt;font color="#0000ff"&gt;Google Search&lt;/font&gt;&lt;/span&gt;&amp;quot; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt"&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#ff0000"&gt;type&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: ; mso-no-proof: yes"&gt;&lt;font style="font-size: 10pt"&gt;&amp;quot;&lt;span&gt;&lt;font color="#0000ff"&gt;GoogleSearch, EPiServer.Templates.Public&lt;/font&gt;&lt;/span&gt;&amp;quot;&lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 10pt" color="#0000ff"&gt; /&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Dynamic Content is very useful feature for editors. Hope that next time I can do this with Google map. &lt;/p&gt;</summary></entry></feed>