<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The SelectedTemplate and duplicate code</title>
	<atom:link href="http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-selectedtemplate-and-duplicate-code</link>
	<description></description>
	<lastBuildDate>Sat, 31 Jul 2010 01:46:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Frederik Vig</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-63</link>
		<dc:creator>Frederik Vig</dc:creator>
		<pubDate>Thu, 12 Nov 2009 09:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-63</guid>
		<description>Ah sorry, then I would just use something like this:
&lt;pre lang=&quot;csharp&quot;&gt;
&lt;a href=&quot;#&quot;
&lt;% if(Container.CurrentPage.IsSelected(CurrentPage)) { %&gt;
   class=&quot;selected&quot;&gt;
&lt;% }%&gt;
&lt;% else { %&gt;
   class=&quot;notselected&quot;&gt;
&lt;% } %&gt;
&lt;/pre&gt;
But again, at that point it might be better to use the SelectedTemplate :).</description>
		<content:encoded><![CDATA[<p>Ah sorry, then I would just use something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>a href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;#&quot;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>Container.<span style="color: #0000FF;">CurrentPage</span>.<span style="color: #0000FF;">IsSelected</span><span style="color: #000000;">&#40;</span>CurrentPage<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">%&gt;</span>
   <span style="color: #FF0000;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;selected&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">%&gt;</span>
   <span style="color: #FF0000;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;notselected&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #000000;">&#125;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>But again, at that point it might be better to use the SelectedTemplate <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Nordin</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-62</link>
		<dc:creator>Erik Nordin</dc:creator>
		<pubDate>Thu, 12 Nov 2009 09:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-62</guid>
		<description>I mean classes that should be there even though it&#039;s not selected. ;)</description>
		<content:encoded><![CDATA[<p>I mean classes that should be there even though it&#8217;s not selected. <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik Vig</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-61</link>
		<dc:creator>Frederik Vig</dc:creator>
		<pubDate>Thu, 12 Nov 2009 09:31:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-61</guid>
		<description>Hi Erik!
If you need to add more classes you just add them with spaces between them: &lt;%# SelectedCssClass(Container.CurrentPage, &quot;class1 class2 class3&quot;) %&gt;.
I like the idea of extending the PageList and the container object. Looking forward to reading about it :).</description>
		<content:encoded><![CDATA[<p>Hi Erik!<br />
If you need to add more classes you just add them with spaces between them: < %# SelectedCssClass(Container.CurrentPage, "class1 class2 class3") %>.<br />
I like the idea of extending the PageList and the container object. Looking forward to reading about it <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Nordin</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-60</link>
		<dc:creator>Erik Nordin</dc:creator>
		<pubDate>Thu, 12 Nov 2009 09:24:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-60</guid>
		<description>One big problem with this approach is if you want to add more css-classes, but I guess you could extend the method for adding this.

I&#039;ve solved this issue by extending the whole PageList and added own templates (if preferred), but I&#039;ve also extended the properties on the Container object with like IsFirst, IsLast, IsSelected, IsAlternating, ItemIndex and ItemCount. That&#039;s all you need to achieve everything ;) Going to blog about it when I have some time over.</description>
		<content:encoded><![CDATA[<p>One big problem with this approach is if you want to add more css-classes, but I guess you could extend the method for adding this.</p>
<p>I&#8217;ve solved this issue by extending the whole PageList and added own templates (if preferred), but I&#8217;ve also extended the properties on the Container object with like IsFirst, IsLast, IsSelected, IsAlternating, ItemIndex and ItemCount. That&#8217;s all you need to achieve everything <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Going to blog about it when I have some time over.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik Vig</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-59</link>
		<dc:creator>Frederik Vig</dc:creator>
		<pubDate>Thu, 12 Nov 2009 08:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-59</guid>
		<description>Hi Eric!
In my experience I mostly end up just adding a class for the selected item. The frontend developer can easily add or change the class by simply changing the second parameter of the SelectedCssClass method (thanks Magne). If the markup and functionality differ much from the regular item, I would use the SelectedTemplate instead, since it makes sense to use in situations when adding everything to the ItemTemplate makes it more complicated and less readable.

You can also use conditional statements
&lt;pre lang=&quot;csharp&quot;&gt;
&lt;% if(Container.CurrentPage.IsSelected(CurrentPage)) { %&gt;
   &lt;!-- selected template markup here --&gt;
&lt;% }%&gt;
&lt;/pre&gt;
I personally find readability more important than having zero duplicated code. So if the regular item and selected item differ much, use the SelectedTemplate. If they are quite similar, like in my example, try to combine them and add an extension or helper method for the logic, but make sure that it does not add difficulties for the frontend developer or others to perform small changes to the code :).</description>
		<content:encoded><![CDATA[<p>Hi Eric!<br />
In my experience I mostly end up just adding a class for the selected item. The frontend developer can easily add or change the class by simply changing the second parameter of the SelectedCssClass method (thanks Magne). If the markup and functionality differ much from the regular item, I would use the SelectedTemplate instead, since it makes sense to use in situations when adding everything to the ItemTemplate makes it more complicated and less readable.</p>
<p>You can also use conditional statements</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span> <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>Container.<span style="color: #0000FF;">CurrentPage</span>.<span style="color: #0000FF;">IsSelected</span><span style="color: #000000;">&#40;</span>CurrentPage<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">%&gt;</span>
   <span style="color: #008000;">&lt;!--</span> selected template markup here <span style="color: #008000;">--&gt;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">%&gt;</span></pre></div></div>

<p>I personally find readability more important than having zero duplicated code. So if the regular item and selected item differ much, use the SelectedTemplate. If they are quite similar, like in my example, try to combine them and add an extension or helper method for the logic, but make sure that it does not add difficulties for the frontend developer or others to perform small changes to the code <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-58</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Thu, 12 Nov 2009 07:57:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-58</guid>
		<description>Hi,

A thought: why would you like to create cs-code instead of using templates, except the fact of NOT duplicating code? Instead  your are having the same functionality in code-behind forcing a gui-developer to re-compile when he/she only would like to change some style?
Maybe im too much of a gui developer but when creating html and styles I don not want to re-compile the project too often! :)

Credits to all your great posts! :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>A thought: why would you like to create cs-code instead of using templates, except the fact of NOT duplicating code? Instead  your are having the same functionality in code-behind forcing a gui-developer to re-compile when he/she only would like to change some style?<br />
Maybe im too much of a gui developer but when creating html and styles I don not want to re-compile the project too often! <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Credits to all your great posts! <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik Vig</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-57</link>
		<dc:creator>Frederik Vig</dc:creator>
		<pubDate>Wed, 11 Nov 2009 17:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-57</guid>
		<description>Hi Magne!
You&#039;re of course right. I&#039;ve renamed the method to SelectedCssClass, which is a much more descriptive name, and added a second parameter where you can add the CSS class. This is also much more friendly for frontend developers, who otherwise would have to contact the backend developer if they needed to rename the CSS class or add another one.</description>
		<content:encoded><![CDATA[<p>Hi Magne!<br />
You&#8217;re of course right. I&#8217;ve renamed the method to SelectedCssClass, which is a much more descriptive name, and added a second parameter where you can add the CSS class. This is also much more friendly for frontend developers, who otherwise would have to contact the backend developer if they needed to rename the CSS class or add another one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magne Thyrhaug</title>
		<link>http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/comment-page-1/#comment-56</link>
		<dc:creator>Magne Thyrhaug</dc:creator>
		<pubDate>Wed, 11 Nov 2009 17:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.frederikvig.com/?p=409#comment-56</guid>
		<description>Hi mistar Frederik!

First off: I very much agree. Remove all duplicate code. Good post :-)

As far as code quality goes, I&#039;ve got a thought: There&#039;s nothing regarding the name of the function (isSelected) that states that it should return the a string. The name instead implies that it should return a boolean value - like (I assume) page.isSelected does. Using a more logical name most certainly would make it easier for the next developer ;)

Another thought: What if you want more classes on the element? &lt;a .... class=&quot;some-random-class &quot;&gt; maybe?

Yay</description>
		<content:encoded><![CDATA[<p>Hi mistar Frederik!</p>
<p>First off: I very much agree. Remove all duplicate code. Good post <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>As far as code quality goes, I&#8217;ve got a thought: There&#8217;s nothing regarding the name of the function (isSelected) that states that it should return the a string. The name instead implies that it should return a boolean value &#8211; like (I assume) page.isSelected does. Using a more logical name most certainly would make it easier for the next developer <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Another thought: What if you want more classes on the element? &lt;a &#8230;. class=&quot;some-random-class &#8220;&gt; maybe?</p>
<p>Yay</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->