<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Forum posts to 'Template Questions'</title>
		<link>http://www.silverstripe.org/template-questions/rss</link>
		<atom:link href="http://www.silverstripe.org/template-questions/rss" rel="self" type="application/rss+xml" />
		<description></description>

		
		<item>
			<title>Controlling Widgets in your Templates - If Statements based on Titles &amp; Widget Counts</title>
			<link>http://www.silverstripe.org/template-questions/show/251970#post251970</link>
			<description>&lt;p&gt;Hey Everybody.  I just had some issues since I'm still learning SilverStripe templating, and I figure there're a few others like me.  So, this is a brief write-up of what I've learned.  Maybe it'll help a few others out there?&lt;/p&gt;&lt;p&gt;&lt;strong&gt;IF Statements that were based on the page/Widget's $Title variable:&lt;/strong&gt;&lt;br /&gt;First of all, two requirements of the template needed me to hide some Widget titles, but show the titles on other pages.&lt;br /&gt;Though it's a bit messy, I realize that some (if not all) Widgets have default titles.&lt;/p&gt;&lt;p&gt;Since I was using the Custom HTML Widget, I put the following code into my template's custom WidgetArea.ss :&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;&amp;lt;% if Title = Info %&amp;gt; &amp;lt;% else %&amp;gt; $Title &amp;lt;% end_if %&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;Since I was so used to PHP, I was expecting the IF statement to require a $ before Title, or quotes around &quot;Info&quot; to signify that it was a string.  Since SilverStripe somehow managed to figure this out itself, I was good.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Altering CSS/HTML Based on Widgets a page may Possess:&lt;/strong&gt;&lt;br /&gt;This new template may have pages that have no side bar-- and if there is no side bar, I needed the HTML to be altered to pertain to the CSS.  In my case, I wanted to alter/add Classes to a div tag.&lt;/p&gt;&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;br /&gt;Desired Page code without widgets:&lt;br /&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;&amp;lt;div id=&quot;container&quot;&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;Desired Page code WITH Widgets:&lt;br /&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;&amp;lt;div id=&quot;container&quot; class=&quot;sidebar&quot;&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;Here is the code I tried:&lt;br /&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;&amp;lt;div id=&quot;container&quot;&lt;br /&gt;   &amp;lt;% control Widgets %&amp;gt;a &amp;lt;% if TotalItems %&amp;gt;class=&quot;sidebar&quot;&amp;lt;% else %&amp;gt; &amp;lt;% end_if %&amp;gt; b &amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;This won't work because I am not controlling the right thing--&lt;/strong&gt;.  &amp;lt;% control Sidebar %&amp;gt; worked out.  See the revised, working code below:  &lt;/p&gt;&lt;p&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;&amp;lt;div id=&quot;container&quot; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;class=&quot;&amp;lt;% control Sidebar %&amp;gt;&amp;lt;% if Widgets.TotalItems %&amp;gt;sidebar&amp;lt;% else %&amp;gt;&amp;lt;% end_if %&amp;gt;&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&quot; &amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;I managed to accomplish the above when remembering that controls/IF statements didn't want the $ sign, and when I realized that Widgets were the children of the Sidebar item.&lt;/p&gt;&lt;p&gt;I realize that some of this may seem pretty easy to an experienced SilverStripe coder, but I wanted to put the word out there.  &lt;br /&gt;&lt;strong&gt;Let me know if this helps you! 8)&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;~Nathan B&lt;br /&gt;&lt;a href=&quot;http://www.polardesign.com/&quot;&gt;Web Design&lt;/a&gt; by &lt;a href=&quot;http://www.polardesign.com&quot;&gt;Polar Design&lt;/a&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;Posted to: Controlling Widgets in your Templates - If Statements based on Titles &amp; Widget Counts &lt;a href=&quot;http://www.silverstripe.org/template-questions/show/251970#post251970&quot;&gt;Show Thread&lt;/a&gt; | &lt;a href=&quot;http://www.silverstripe.org/template-questions/show/251970#post251970&quot;&gt;Post Reply&lt;/a&gt;</description>
			<pubDate>Sat, 10 Jan 2009 08:35:09 +1300</pubDate>
			<dc:creator>NathanB</dc:creator>
			<guid>http://www.silverstripe.org/template-questions/show/251970#post251970</guid>
		</item>
		

	</channel>
</rss>