<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tridion Developer &#187; Helpful Tridion tips</title>
	<atom:link href="http://www.tridiondeveloper.com/category/tips-and-tricks/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tridiondeveloper.com</link>
	<description>Tridion Development portfolio and blog</description>
	<lastBuildDate>Thu, 26 Jan 2012 05:44:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using XPath to find XML Elements with Inline/Default Namespace and Null Prefix</title>
		<link>http://www.tridiondeveloper.com/xpath-query-for-tags-with-null-prefix</link>
		<comments>http://www.tridiondeveloper.com/xpath-query-for-tags-with-null-prefix#comments</comments>
		<pubDate>Thu, 26 Jan 2012 05:36:29 +0000</pubDate>
		<dc:creator>Nickoli Roussakov</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=401</guid>
		<description><![CDATA[On the last SDL Tridion Community Webinar, Dominic Cronin suggested a great alternative to Regex for finding, adding, removing, or replacing certain elements or attributes, such as Component Links within Components (or Pages).  The more data-safe approach is to manipulate the Component source as an XML document [via XPath] rather than regex.  I gave it [...]]]></description>
			<content:encoded><![CDATA[<p>On the last SDL Tridion Community Webinar, Dominic Cronin suggested a great alternative to Regex for finding, adding, removing, or replacing certain elements or attributes, such as Component Links within Components (or Pages).  The more data-safe approach is to manipulate the Component source as an XML document [via XPath] rather than regex.  I gave it a shot, except that getting (what seems like) a simple XPath query to work took way more effort than I anticipated.  All of this due to a little unknown detail about XPath queries for items in the default namespace without a prefix.</p>
<p><span id="more-401"></span></p>
<p>In this scenario, the Tridion XML source for a component has elements with inline (or default) xhtml namespaces declared right on the element that we&#8217;re searching for, and no prefix. For example, in the XML below such elements are the anchor and paragraph tags:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-16&#8243;?&gt;<br />&lt;Content xmlns=&#8221;uuid:7F1745CA-CCFE-4032-BAD7-5699F4149D3B&#8221;&gt;<br /> &lt;Title&gt;Hello Internets!&lt;/Title&gt;<br /> &lt;Introduction&gt;<br /> &lt;div style=&#8221;TEXT-ALIGN: left&#8221; xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;Welcome to our website.    This is some random content that isn&#8217;t doing very much, except <strong>&lt;a href=&#8221;http://google.com&#8221;&gt;this link&lt;/a&gt;</strong><br /> &lt;/div&gt;<br /> &lt;/Introduction&gt;<br /> &lt;Body&gt;<br /> <strong>&lt;p xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;This is some more body content that has been put into the page.&lt;/p&gt;</strong><br /> &lt;/Body&gt;<br />&lt;/Content&gt;</p>
<p>A basic XPath query such as myXmlDocument.SelectNode(&#8220;//p&#8221;) should return all the &lt;p&gt; elements in the document, however, since they&#8217;re part of the default &#8220;http://www.w3.org/1999/xhtml&#8221; namespace, you get nothing back from your search &#8211; very annoying: thanks XPath engine for making it so hard! If only there had been a prefix, e.g. &lt;p xmlns:xhtml=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt; then the XPath query would be a no brainer: myXmlDocument.SelectNode(&#8220;//xhtml:p&#8221;), and we&#8217;d select all the &lt;p&gt; nodes in the document within that namespace.</p>
<p>Actually, even though you don&#8217;t see a prefix in the above example, there actually is one. It&#8217;s called the NULL prefix. And the way you select nodes with a NULL prefix in C# is as follows:</p>
<p>XmlDocument componentXml = componentItem.GetAsXmlDocument();<br />XmlNamespaceManager nsMgr = new XmlNamespaceManager(componentXml.NameTable);<br /><strong>nsMgr.AddNamespace(&#8220;null&#8221;, &#8220;http://www.w3.org/1999/xhtml&#8221;);</strong><br />foreach (XmlElement pNode in componentXml.SelectNodes(&#8220;<strong>//null:p</strong>&#8220;, nsMgr))<br />{<br />    //do stuff with the pNode,<br />    //such as (random example) remove it completely from the document.</p>
<p>    pNode.ParentNode.RemoveChild(pNode);<br />}</p>
<p>Notice above, the xhtml namespace is added to the NamespaceManager with the &#8220;null&#8221; prefix, and then the XPath query selects the &lt;p&gt; tag with that prefix? That&#8217;s it!</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/xpath-query-for-tags-with-null-prefix/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Compression in SDL Tridion (minification and obfuscation. CSS too)</title>
		<link>http://www.tridiondeveloper.com/javascript-compression-in-sdl-tridion</link>
		<comments>http://www.tridiondeveloper.com/javascript-compression-in-sdl-tridion#comments</comments>
		<pubDate>Tue, 20 Dec 2011 01:44:47 +0000</pubDate>
		<dc:creator>Nickoli Roussakov</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=341</guid>
		<description><![CDATA[I&#8217;ve been building up my jot notes throughout the year and finally got the chance to make them into publishable form, which lead me to this sudden series of articles. Thanks, John, for letting me post on your site. To achieve maximum compression on a JavaScript file, minification is not enough.  Obfuscation is where it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been building up my jot notes throughout the year and finally got the chance to make them into publishable form, which lead me to this sudden series of articles.  Thanks, John, for letting me post on your site.</p>
<p>To achieve maximum compression on a JavaScript file, minification is not enough.  Obfuscation is where it&#8217;s at.  This means replacing variable names to the shortest amount of characters (or bytes) that the language syntax allows.  For example: var myReallyLongVariableName=&#8221;foobar&#8221; would become var a=&#8221;foobar&#8221;; but only within its scope, and so on.  You basically have to implement a decent chunk of code that usually comes as part of any language interpreter or compiler.  It&#8217;s quite a bit more involved than minification alone.  My point is, use a proven package that does this and just hook it up to the best CMS known to man.</p>
<p>My preferred way is actually to not store JavaScript or CSS in Tridion.  Put it with the rest of your website&#8217;s code into the repository like TFS or Subversion.  Basically, bundle it into your build process which should go through Change Management with the likes of JAR/DLL files and DB packages.  JS is code after all.  This way you can just add a step to your build process.  Ask the build master to crunch the JS/CSS through a compressor (possibly as a manual step) before or automate within an ANT, NANT or MSBuild script.  If, however, you are a content author or Support person that hates dealing with your org&#8217;s Change Management process or have some other reason to store js and/or CSS code as easily publishable as content, then this is for you.</p>
<p><span id="more-341"></span></p>
<p>A requirement I often get requests for is to minify and obfuscate JS files which are stored in Tridion, either in Multimedia Components or pasted into a text field of a normal component.    Minification is trivial.  Simply remove the extra whitespace and comments.  Obfuscation, however, is a bit more involved as I mentioned above.  So let&#8217;s find a good JS compressor package that&#8217;s available today.</p>
<p>YUI Compressor is the best minification and obfuscation library that is out there.  It was created by engineers at Yahoo!.  Since the original package is in Java, but Tridion templating is done in C#, we&#8217;ll turn to the YUI Compressor .NET port (link is below).</p>
<p>There are two classes with methods that do what we need to do:</p>
<ol>
<li>CSSCompressor.Compress(<em>string</em>)</li>
<li>JavaScriptCompressor.Compress(<em>string</em>)</li>
</ol>
<p>Both of the above return string.  So all we need to do is extract the CSS or JavaScript content from our component as a string, call the YUI Compressor methods and publish the CSS or JS file.</p>
<p>There are a few ways that a CSS/JS file can be published:</p>
<p>1) Static publishing model &#8211; the component holding the JS is added to a Page and published (using a simple page template).  Our fellow Tridion community member, Jonathan Whiteside, has an excellent article series that dives into these details in his discussion on Tridion CSS Minification (<a href="http://blog.building-blocks.com/2011/01/tridion-tbb-automatically-minify-css-javascript-on-publish" target="_blank">http://blog.building-blocks.com/2011/01/tridion-tbb-automatically-minify-css-javascript-on-publish</a>).</p>
<p>2) Dynamic publishing model &#8211; the component is published via a dynamic component template that relies on a TBB which extracts the JS content from the component and calls the AddBinary method with a Structure Group URI as a parameter.  No Page is necessary here, but you do need at least the file system Broker running.</p>
<p>My aim in this post is not to get into the details of #1 or #2 above.  I will show an example that extracts the JS or CSS as a string from the MM Component (using Jonathan&#8217;s method), call on the YUI Compressor to obfuscate and minify, and place the compress string as a variable onto the Package.  You can do whatever you wish with it at that point &#8211; put the TBB into a static or dynamic CT.</p>
<p>Here we go:</p>
<ol>
<li>Download the .NET port of the YUI Compressor from here: <a href="http://yuicompressor.codeplex.com/" target="_blank">http://yuicompressor.codeplex.com/</a></li>
<li>Take these DLLs and put them in the GAC or the Tridion Bin folder on your Content Manager server(s).  Make sure these DLLs are on all the CM servers that the TBB will need to execute on (all load balanced CM nodes, Dev, QA, Prod, etc).  Make sure to submit a Change Request to have these DLLs installed on anything past the Development environment, but if you have a good, no BS rep with your server admins (like I always do <img src='http://www.tridiondeveloper.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , this shouldn&#8217;t be a problem.</li>
<li>Make sure the Template Base class (which is part of Will&#8217;s Get Linked Components extension) is added into your Visual Studion project. </li>
<li>Create a new Template Building Block class in Visual Studio with this code:
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
using System;
using System.Text;
using System.Text.RegularExpressions;
using Tridion.ContentManager;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Templating;
using Tridion.ContentManager.Templating.Assembly;
using ContentBloom.Tridion.B2C.Templates.Base;
using System.IO;
using Yahoo.Yui.Compressor;
using System.Globalization;

namespace ContentBloom.Tridion.B2C.Templates
{
    [TcmTemplateTitle(&quot;Compress JS and CSS using YUI Compressor&quot;)]
    public class CompressYUI : TemplateBase
    {
        enum BinaryType
        {
            JS, CSS, Other
        }

        public override void Transform(Engine engine, Package package)
        {
            // Initialize
            Initialize(engine, package);
            string codeContent;

            // Get CSS Content
            Logger.Debug(&quot;Retrieving code from Component.&quot;);
            Component comp = this.GetComponent();
            string filename = Utilities.GetFilename(comp.BinaryContent.Filename);
            BinaryType bt = GetFileType(filename);
            if(bt == BinaryType.JS || bt == BinaryType.CSS)
            {
                string needsCompression = package.EvaluateExpression(&quot;Component.Metadata.compress&quot;);
                // if the &quot;Compress&quot; field is not specified, then default it to True.
                if (string.IsNullOrEmpty(needsCompression) || needsCompression == &quot;True&quot;)
                {
                    codeContent = GetCodeContent(comp);

                    try
                    {
                        Logger.Debug(&quot;Before minification:\n&quot; + codeContent);
                        switch (bt)
                        {
                            case BinaryType.CSS:
                                codeContent = CssCompressor.Compress(codeContent);
                                break;
                            case BinaryType.JS:
                                codeContent = JavaScriptCompressor.Compress(codeContent, true, true, false, false, -1, Encoding.UTF8, new CultureInfo(&quot;en-US&quot;, false));
                                break;
                        }
                        Logger.Debug(&quot;After minification:\n&quot; + codeContent);
                    }
                    catch (Exception e)
                    {
                        string message = e.Message;
                        if (e.Message.Contains(&quot;syntax error&quot;))
                        {
                            message = &quot;There is a problem with the encoding of the file. Please change the encoding of the file to UTF-8 WITH NO BYTE ORDER MARK/UTF-8 without signature.&quot;;
                        }
                        throw new InvalidDataException(message, e);
                    }

                    //push to Output.
                    package.PushItem(&quot;Output&quot;, package.CreateStringItem(ContentType.Text, componentCount.ToString(codeContent)));
                }
                else
                {
                    Logger.Info(&quot;Component metadata \&quot;Compress\&quot; field specifies to avoid compression. Therefore, exiting.&quot;);
                }
            }
            else
            {
                Logger.Info(&quot;No CSS or JS file found, so nothing to do.&quot;);
            }
        }

        private BinaryType GetFileType(string filename)
        {
            Logger.Debug(&quot;Entering method GetFileType&quot;);
            BinaryType bt = BinaryType.Other;
            filename = filename.ToLower();
            Logger.Debug(&quot;filename=&quot; + filename);
            if (filename.EndsWith(&quot;.css&quot;))
            {
                bt = BinaryType.CSS;
            }
            else if (filename.EndsWith(&quot;.js&quot;))
            {
                bt = BinaryType.JS;
            }
            Logger.Debug(&quot;Exiting method GetFileType&quot;);
            return bt;
        }

        ///
        /// Get the CSS content in plain text from the current component
        ///
        /// CSS content in plain text
        private string GetCodeContent(Component c)
        {
            // code path
            string codeContent = string.Empty;

            // read the css into a string
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] binary = c.BinaryContent.GetByteArray();
            if (binary != null) codeContent = encoding.GetString(binary, 0, binary.Length);

            return codeContent;
        }
    }
}
</pre>
</div>
</pre>
</li>
<li>Finally, add the TBB to your Component Template and enjoy the sexiest minified and obfuscated JavaScript.</li>
</ol>
<h2>Minify/Obfuscate Only on Demand</h2>
<p>You can go one step further and add a bit of logic to minify and obfuscate only for certain scripts, e.g. obfuscate one, but not the other.  Here&#8217;s what you can do&#8230;</p>
<p>In your JavaScript Multimedia Component schema add a couple of Text metadata fields:</p>
<ol>
<li>Field name: &#8220;Minify&#8221;.  Value: Select from Dropdown &#8220;Yes/No&#8221;.</li>
<li>Field name: &#8220;Obfuscate&#8221;.  Value: Select from Dropdown &#8220;Yes/No&#8221;.</li>
</ol>
<p>Modify the TBB above to read these fields from the Component and minify/obfuscate accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/javascript-compression-in-sdl-tridion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More fun with Dreamweaver Templates &#8211; TemplateRepeatCount</title>
		<link>http://www.tridiondeveloper.com/more-fun-with-dreamweaver-templates-templaterepeatcount</link>
		<comments>http://www.tridiondeveloper.com/more-fun-with-dreamweaver-templates-templaterepeatcount#comments</comments>
		<pubDate>Sun, 18 Dec 2011 05:08:43 +0000</pubDate>
		<dc:creator>Nickoli Roussakov</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=318</guid>
		<description><![CDATA[Quite a while back (in &#8217;09&#8242; I think) I replied to a thread on the sdltridionworld forum regaring how to get the total count of your elements when doing a TemplateBeginRepeat inside a DWT. For example when you have a special css class that needs to be applied to the last item in the list. [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a while back (in &#8217;09&#8242; I think) I replied to a thread on the sdltridionworld forum regaring how to get the total count of your elements when doing a TemplateBeginRepeat inside a DWT.</p>
<p>For example when you have a special css class that needs to be applied to the last item in the list.</p>
<pre>
<div class="syntaxhighlighter htmlscript">
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/contact/&quot;&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/sitemap/&quot;&gt;Site Map&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;last&quot;&gt;&lt;a href=&quot;/terms-of-use/&quot;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</div>
</pre>
<p>An intuitive approach is to have a function or a variable that provides the count so that you can use syntax like this:</p>
<pre>
<div class="syntaxhighlighter htmlscript">
&lt;ul&gt;
 &lt;!-- TemplateBeginRepeat name=&quot;Component.LinkList&quot; --&gt;
&lt;li&gt;&lt;a href=&quot;@@MyUrlField@@&quot;&gt;@@MyUrlText@@&lt;/a&gt;&lt;/li&gt;

  &lt;!-- TemplateBeginIf cond=&quot;TemplateRepeatIndex == TemplateRepeatCount()-1 --&gt;
&lt;li class=&quot;last&quot;&gt;&lt;a href=&quot;@@MyUrlField@@&quot;&gt;@@MyUrlText@@&lt;/a&gt;&lt;/li&gt;

  &lt;!-- TemplateEndIf --&gt;
&lt;!-- TemplateEndRepeat --&gt;
&lt;/ul&gt;
</div>
</pre>
<p>I&#8217;ll post that function later once I dig up the code again.  Though, here is another approach which I used one late night in the office wanting to finish a template.  It was past my sys admin&#8217;s office time, so I couldn&#8217;t ask him to deploy a new Custom Functions DLL to the CM server&#8217;s GAC/bin, but I just had to get the template done by end of day &#8211; I was in the zone.  Besides, I couldn&#8217;t let it linger the next day.  </p>
<p>
So here is a quick C# fragment that should be used in sequence after Will Price&#8217;s &#8220;Get Linked Components&#8221; extension (just Google it if you don&#8217;t know.  It&#8217;s the best thing since the combustion engine/sliced bread/eh&#8230;SDL Tridion CMS).</p>
<p>Anyway, just drop this C# Fragment in after &#8220;Get Linked Components&#8221;:</p>
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
&lt;%@ Import Namespace=&quot;Tridion.ContentManager.ContentManagement.Fields&quot;%&gt;
&lt;%@ Import Namespace=&quot;System.Collections.Generic&quot;%&gt;

/// This TBB loops through all the items in the package and for any items which are Component Arrays
/// adds a new package item with the array entry count.  This is useful when a Dreamweaver TBB needs to know
/// the total count of components or when needing to know if you're on the last component.

List&lt;KeyValuePair&lt;string, Item&gt;&gt; extractedComponentLists = new List&lt;KeyValuePair&lt;string, Item&gt;&gt;();
foreach (KeyValuePair&lt;string, Item&gt; kvp in package.GetEntries())
{
    if (kvp.Value.ContentType == ContentType.ComponentArray)
    {
        //get count
        extractedComponentLists.Add(kvp);
    }
}

// This code has to be kept in a separate loop since you can't modify the package.GetEntries collection while looping through it.
foreach (KeyValuePair&lt;string, Item&gt; kvp in extractedComponentLists)
{
    IComponentPresentationList linkCollectionCPList = ComponentPresentationList.FromXml(kvp.Value.GetAsString());
    int componentCount = linkCollectionCPList.Count;
    package.PushItem(kvp.Key + &quot;Count&quot;, package.CreateStringItem(ContentType.Number, componentCount.ToString()));
}
</pre>
</div>
</pre>
<p>&nbsp;</p>
<p>After this TBB runs, you&#8217;ll get a new entry on the package with the count for each &#8220;Tridion/Component[]&#8221; item type that &#8220;Get Linked Components&#8221; fetches.  So if we had a multi-value component link field in the component called &#8220;LinkList&#8221;, then &#8220;Get Linked Components&#8221; should fetch a component array and call it after your field name &#8211; something like &#8220;LinkList&#8221;.  Then after this DWT a new entry will appear called &#8220;LinkListCount&#8221;.</p>
<p>Use it like this in your DWT:</p>
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
&lt;ul&gt;
&lt;!-- TemplateBeginRepeat name=&quot;Component.LinkList&quot; --&gt;
&lt;li&gt;&lt;a href=&quot;@@MyUrlField@@&quot;&gt;@@MyUrlText@@&lt;/a&gt;
&lt;li&gt;&lt;!-- TemplateBeginIf cond=&quot;TemplateRepeatIndex == LinkListCount-1 --&gt; 
&lt;li&gt;&lt;a href=&quot;@@MyUrlField@@&quot;&gt;@@MyUrlText@@&lt;/a&gt;
&lt;li&gt;&lt;!-- TemplateEndIf --&gt;
&lt;!-- TemplateEndRepeat --&gt;
&lt;/ul&gt;
</pre>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/more-fun-with-dreamweaver-templates-templaterepeatcount/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get and Set Variables in DWTs</title>
		<link>http://www.tridiondeveloper.com/get-and-set-variables-in-dwts</link>
		<comments>http://www.tridiondeveloper.com/get-and-set-variables-in-dwts#comments</comments>
		<pubDate>Sat, 17 Dec 2011 00:22:38 +0000</pubDate>
		<dc:creator>Nickoli Roussakov</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[Tridion building block]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=295</guid>
		<description><![CDATA[Here is a creative and useful set of Dreamweaver Custom Functions that allow instantiating your own variables in a Dreamweaver Tridion template.  Credit goes out to my fellow team members Trevor Bartlett and Riyaz Hameed. You can do stuff like this: Here is the code:]]></description>
			<content:encoded><![CDATA[<p>Here is a creative and useful set of Dreamweaver Custom Functions that allow instantiating your own variables in a Dreamweaver Tridion template.  Credit goes out to my fellow team members Trevor Bartlett and Riyaz Hameed.</p>
<h2>You can do stuff like this:</h2>
<pre>
<div class="syntaxhighlighter htmlscript">
&lt;!-- TemplateBeginRepeat name=&quot;Field.columnSection&quot; --&gt;
  &lt;div class=&quot;wpsPortlet&quot;&gt;
    &lt;div class=&quot;wpsPortletTitle&quot;&gt;
      &lt;br /&gt;@@Field.title@@&lt;/div&gt;
    @@SetVariable(“columnSectionIndex”, &quot;${TemplateRepeatIndex}&quot;)@@
    &lt;!-- TemplateBeginRepeat name=&quot;Field.subColumnSection&quot; --&gt;
    @@GetVariable(&quot;columnSectionIndex&quot;)@@
    &lt;!-- TemplateBeginRepeat name=&quot;Field.subTitle&quot; --&gt;
       …
    &lt;!-- TemplateEndRepeat --&gt;
  &lt;/div&gt;
&lt;!-- TemplateEndRepeat --&gt;
<h2></h2>
<h2>Here is the code:</h2>
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
/// &lt;summary&gt;
/// Sets a varialbe in the package to the name and value specifed. Also removes any other variable that was set with the same name before.
/// &lt;/summary&gt;
/// &lt;param name=&quot;variableName&quot;&gt;Name of the varialbet&lt;/param&gt;
/// &lt;param name=&quot;value&quot;&gt;Value of the variable&lt;/param&gt;
[TemplateCallable()]
public string SetVariable(string variableName, object value)
{
    //Remove the old variable and set the new variable
    _engine.PublishingContext.RenderContext.ContextVariables.Remove(variableName);
    _engine.PublishingContext.RenderContext.ContextVariables.Add(variableName, value);

    return &quot;&quot;;
}

/// &lt;summary&gt;
/// Gets a varialbe from the publishing context.
/// &lt;/summary&gt;
/// &lt;param name=&quot;variableName&quot;&gt;Name of the variable&lt;/param&gt;
[TemplateCallable()]
public object GetVariable(string variableName)
{
    //Get the varialbe
    return _engine.PublishingContext.RenderContext.ContextVariables[variableName];
}
</pre>
</div>
</pre>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/get-and-set-variables-in-dwts/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting used items using the core service</title>
		<link>http://www.tridiondeveloper.com/getting-used-items-using-the-core-service</link>
		<comments>http://www.tridiondeveloper.com/getting-used-items-using-the-core-service#comments</comments>
		<pubDate>Sun, 27 Nov 2011 18:52:11 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[Tridion 2011]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=285</guid>
		<description><![CDATA[Just wanted to post up a quick code snippet showing how to get a list of used items XML using the SDL Tridion 2011 core service.  Why?  Well previously the API typically used to work like itemType.GetListUsedItems() (where itemType is a Component or Page object etc), where as now the &#8216;Using&#8217; and &#8216;Used&#8217; items are [...]]]></description>
			<content:encoded><![CDATA[<p>Just wanted to post up a quick code snippet showing how to get a list of used items XML using the SDL Tridion 2011 core service.  Why?  Well previously the API typically used to work like <em>itemType.GetListUsedItems()</em> (where itemType is a Component or Page object etc), where as now the &#8216;Using&#8217; and &#8216;Used&#8217; items are read using a filter via the core service client method <em>.GetListXML()</em>.</p>
<p><span id="more-285"></span></p>
<p>The example:</p>
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
            // Create a filter
            UsedItemsFilterData usingItemsFilterData = new UsedItemsFilterData
            {
                BaseColumns = ListBaseColumns.Id, // to specify the detail in the XML
                ItemTypes = new[] { ItemType.Folder, ItemType.Schema, ItemType }  // to specify certain items
            };
            // Get the XML by calling .GetListXml on the client (assumes you have a 'client' object already)
            XElement usingXML = client.GetListXml(&quot;tcm:4-283&quot;, usingItemsFilterData);
</pre>
</div>
</pre>
<p>If you&#8217;re looking to get the Using Items, for an item, you can simply use a UsingItemsFilterData filter in exactly the same way &#8211; enjoy <img src='http://www.tridiondeveloper.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/getting-used-items-using-the-core-service/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove HTML whitespace from the template output</title>
		<link>http://www.tridiondeveloper.com/remove-whitespace-dwt-tridion-output</link>
		<comments>http://www.tridiondeveloper.com/remove-whitespace-dwt-tridion-output#comments</comments>
		<pubDate>Mon, 10 Oct 2011 23:54:03 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=248</guid>
		<description><![CDATA[HTML published from Tridion is typically created using Tridion Dreamweaver Templates (DWTs).  These templates can involve a lot of ‘If’ statements to check that values exist or what their value is etc.  I like to put line breaks between each DWT statement so that its easier to read and work with, which usually looks something [...]]]></description>
			<content:encoded><![CDATA[<p>HTML published from Tridion is typically created using Tridion Dreamweaver Templates (DWTs).  These templates can involve a lot of ‘If’ statements to check that values exist or what their value is etc.  I like to put line breaks between each DWT statement so that its easier to read and work with, which usually looks something like this (actually it can get a lot crazier than this!):</p>
<pre><a href="http://www.tridiondeveloper.com/wp-content/uploads/2011/10/sdl-tridion-dwt-snippet.png"><img class="alignnone size-full wp-image-263" title="sdl-tridion-dwt-snippet" src="http://www.tridiondeveloper.com/wp-content/uploads/2011/10/sdl-tridion-dwt-snippet.png" alt="" width="320" height="131" /></a>
</pre>
<p><span id="more-248"></span></p>
<p>The only issue with doing this is that HTML white-space is preserved, resulting in tonnes of extra line breaks in the published HTML.  I&#8217;m anal about HTML, (there will be NO extra line breaks, NOT ON MY WATCH!) so I wrote a little TBB to clean up any lines that are blank, here&#8217;s the code:</p>
<pre>
<div class="syntaxhighlighter htmlscript">
<pre class="brush: jscript; title: ; notranslate">
        public override void Transform(Engine engine, Package package)
        {
            this.Initialize(engine, package);

            //get output item from the package
            string outputName = Package.OutputName;
            Item outputItem = package.GetByName(outputName);

            // if the output is text based, lets clean it up
           if ((outputItem.Type == PackageItemType.String))
            {
                Logger.Debug(&quot;Output exists, cleaning empty lines&quot;);
                string uglyOutput = outputItem.GetAsString();

                //Gets the converted output string
                string fixedOutput = Regex.Replace(uglyOutput, @&quot;^\s*$\n&quot;, string.Empty, RegexOptions.Multiline);
                //Remove the old output string, and put the new one in place
                Logger.Debug(&quot;Output cleaned, updating item in package&quot;);
                package.Remove(outputItem);
                outputItem.SetAsString(fixedOutput);
                package.PushItem(outputName, outputItem);
            }
        }
</pre>
</div>
</pre>
<p>The usual caveat about the code published here is that it is using the <a href="http://www.sdltridionworld.com/community/extension_overview/templatingbase.aspx">SDL Tridion base classes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/remove-whitespace-dwt-tridion-output/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Online SDL Tridion resources</title>
		<link>http://www.tridiondeveloper.com/online-sdl-tridion-resources</link>
		<comments>http://www.tridiondeveloper.com/online-sdl-tridion-resources#comments</comments>
		<pubDate>Fri, 05 Aug 2011 11:37:49 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[Tridion 2011]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=173</guid>
		<description><![CDATA[In the past couple of months a number of great online resources have popped up to help with SDL Tridion development, implementation topics and environment configuration.  These links are mostly promoted on Twitter, so in the event you have missed them, I&#8217;ve made a compilation of some favourites. SDL Tridion 2011 online documentationSDL&#8217;s own online [...]]]></description>
			<content:encoded><![CDATA[<p>In the past couple of months a number of great online resources have popped up to help with SDL Tridion development, implementation topics and environment configuration.  These links are mostly promoted on Twitter, so in the event you have missed them, I&#8217;ve made a compilation of some favourites.</p>
<p><span id="more-173"></span><a title="SDL Tridion online documentation" href="http://sdllivecontent.sdl.com/LiveContent/">SDL Tridion 2011 online documentation</a><br />SDL&#8217;s own online documentation covers everything from installation of the CME, Content Delivery (very useful as major changes have been made in 2011), upgrading, GUI extensions, Smart Target, Translation Manager and the new Online Marketing Explorer.</p>
<p>To access the system you may need to log in with the following details:<br />Username: visitor<br />Password: sdltridion</p>
<p><a title="SDL Tridion World" href="https://www.sdltridionworld.com/articles/sdltridion2011/index.aspx">SDL Tridion World</a><br />There have been tonnes of new posts to SDL Tridion world since the release of 2011.  Including step by step guides for some of the new features, including setting up the new <a title="Setting up the SDL Tridion oData service" href="https://www.sdltridionworld.com/articles/sdltridion2011/tutorials/deployer-and-odata-1.aspx">0Data service</a> and configuring your own <a title="Setting up an SDL Tridion Gui Extension" href="https://www.sdltridionworld.com/articles/sdltridion2011/tutorials/GUIextensionIn8steps.aspx">GUI Extension</a>.</p>
<p><a title="Tridion MVC Dot Net" href="https://github.com/rainmaker2k/TridionMVCDotNet">Rainmaker&#8217;s Tridion /.Net MVC</a> <br />Kah Tang has placed a sample .NET MVC project online.  The project uses content via Tridion&#8217;s Dynamic Delivery.  Worth checking out not only for the MVC, but as an example of .NET using Tridion broker content.</p>
<p><a title="Building blocks blog" href="http://blog.building-blocks.com/">Building Blocks Blog</a><br />The building blocks team have created some great examples showing how to use the new Core service for creating and importing content into  Tridion.</p>
<p>SDL Tridion community posts<br />A number of great posts have come out of the SDL Tridion community including:<br />Nuno Linhares: <a href="http://nunolinhares.blogspot.com/2011/07/manually-configuring-tridion-2011-net.html">Manually configuring a Tridion 2011 .NET Content Deployer Instance</a><br />Yoav Niran: <a href="http://yoavniran.wordpress.com/tag/extensions/">Tonnes of great GUI extensions and tutorials</a><br />Walter Van Der Heiden: <a href="http://tridionarchitect.blogspot.com/2011/03/generating-qr-code-with-sdl-tridion.html">Using SDL Tridion to generate QR codes</a><br />Steve Sidell: <a href="http://www.youtube.com/watch?v=C8nbUnfDnOY&amp;feature=youtu.be">SDL SmartTarget: Delivering advanced targeting, profiling and personalization tools</a></p>
<p><a title="Tridion Pratice Cookbook" href="https://code.google.com/p/tridion-practice/">Tridion Practice Cookbook</a><br />Recently set up by <a href="http://www.dominic.cronin.nl/weblog">Dominic Cronin </a>the Tridion practice cookbook to not only show how to implement SDL Tridion features, but how features can/should be coded, it&#8217;s a great initiative and I hope it catches on within the community.</p>
<p>I hope I&#8217;ve not missed anything off, if so please let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/online-sdl-tridion-resources/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GetObject vs Get(ItemType)</title>
		<link>http://www.tridiondeveloper.com/getobject-vs-getitemtype</link>
		<comments>http://www.tridiondeveloper.com/getobject-vs-getitemtype#comments</comments>
		<pubDate>Thu, 14 Oct 2010 16:26:48 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[get items from tridion]]></category>
		<category><![CDATA[getObject]]></category>
		<category><![CDATA[publication]]></category>
		<category><![CDATA[tdse]]></category>
		<category><![CDATA[WebDav]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=121</guid>
		<description><![CDATA[This is more of a ‘note to self’ as I’m constantly being caught out when getting an object from Tridion using the various TDSE methods. I’ll use the example of getting a folder via the TDSE object.  To do this you have two ways: The TDSE.GetFolder(“ID”, Publication Object) Method The TDSE.GetObject(“ID”, OpenMode, Publication, ReadFilter) Method [...]]]></description>
			<content:encoded><![CDATA[<p>This is more of a ‘note to self’ as I’m constantly being caught out when getting an object from Tridion using the various TDSE methods.</p>
<p><span id="more-121"></span></p>
<p>I’ll use the example of getting a folder via the TDSE object.  To do this you have two ways:</p>
<ul>
<li>The TDSE.GetFolder(“ID”, Publication Object) Method</li>
<li>The TDSE.GetObject(“ID”, OpenMode, Publication, ReadFilter) Method</li>
</ul>
<p>The <strong>GetFolder</strong> will always need a valid Publication object, where as the <strong>GetObject</strong> will allow a null to be thrown in.</p>
<p>I’ve done this a thousand times:</p>
<ul>
<li>TDSE.GetFolder(“tcm:1-123-2”, null);</li>
</ul>
<p>Then spent about 20 minutes checking the XML, the webdav etc etc.</p>
<p>The benefit of being able to pass the null, is that if the Publication object doesn&#8217;t exist, you don&#8217;t have to create it surely making the <strong>GetObject</strong> a far superior method to use&#8230; just remember to cast to the correct Tridion item type:</p>
<ul>
<li>Folder fld = tdse.GetObject(&#8230;) as Folder</li>
</ul>
<p>Please tell me I’m not alone in being constantly caught out by this!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/getobject-vs-getitemtype/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Displaying item XML in the GUI with interface extensions</title>
		<link>http://www.tridiondeveloper.com/displaying-item-xml-in-the-gui-with-interface-extensions</link>
		<comments>http://www.tridiondeveloper.com/displaying-item-xml-in-the-gui-with-interface-extensions#comments</comments>
		<pubDate>Mon, 06 Sep 2010 15:37:40 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Development and templating]]></category>
		<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[GUI Extension]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=116</guid>
		<description><![CDATA[Yoav Niran has written and blogged about another great Tridion GUI extension.  This time  providing a really elegant solution for developers/users that need to see the full XML content of an given item without having to (in my case) faff about with ID&#8217;s, Paths or templates. I can&#8217;t think of any project where at some point [...]]]></description>
			<content:encoded><![CDATA[<p>Yoav Niran has written and <a href="http://yoavniran.wordpress.com/2010/08/30/the-item-xml-display-tridion-gui-extension/">blogged</a> about another great Tridion GUI extension.  This time  providing a really elegant solution for developers/users that need to see the full XML content of an given item without having to (in my case) faff about with ID&#8217;s, Paths or templates.</p>
<p><span id="more-116"></span></p>
<p>I can&#8217;t think of any project where at some point in the build I&#8217;ve needed to check the item&#8217;s XML, usually to get a path, check check security or some other content related detail.</p>
<p>My solutions to this have varied depending on the situation:</p>
<p><strong>A custom template</strong> &#8211; A small bit of code as a Tridion page template, where the TCM is added directly into the code, which is going into the Tridion database and returns XML.  Essentially update the code with the new TCMID and preview the page.  This is fine but it&#8217;s a bit slow in terms of updating and previewing.</p>
<p><strong>Webdav </strong>- Great, but  this only works when you want to view components, schema and templates.</p>
<p><strong>Using the windows run menu</strong> &#8211; Entering the item TCM ID in the windows run menu will bring back the given items XML, this is great, but only works if you&#8217;re on the actual CM machine.</p>
<p>Thanks Yoav&#8217;s, this is a fantastic solution, plus all of the above are now redundant!</p>
<p>What would be cool if these could be part of the installed GUI with configurable security to only show this to members of a certain group and to hide from others that simply don&#8217;t need it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/displaying-item-xml-in-the-gui-with-interface-extensions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some notes about Tridion item naming</title>
		<link>http://www.tridiondeveloper.com/some-notes-about-tridion-item-naming</link>
		<comments>http://www.tridiondeveloper.com/some-notes-about-tridion-item-naming#comments</comments>
		<pubDate>Wed, 31 Mar 2010 16:02:15 +0000</pubDate>
		<dc:creator>John Winter</dc:creator>
				<category><![CDATA[Helpful Tridion tips]]></category>
		<category><![CDATA[Migration]]></category>
		<category><![CDATA[Guidlines]]></category>
		<category><![CDATA[Naming]]></category>
		<category><![CDATA[WebDav]]></category>

		<guid isPermaLink="false">http://www.tridiondeveloper.com/?p=104</guid>
		<description><![CDATA[I’ve just recently written a script which imported a load of content from flat files into Tridion.  Using the flat files, the script creates the various folders, pages and components etc that it needed.  Unfortunately I cannot share the code as the client contract permits me to do (plus it was a throw-away tool written [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve just recently written a script which imported a load of content from flat files into Tridion.  Using the flat files, the script creates the various folders, pages and components etc that it needed.  Unfortunately I cannot share the code as the client contract permits me to do (plus it was a throw-away tool written specifically around the format of the import data) but I can share a couple of titbits that I learnt about item naming and WebDAV lengths.</p>
<p><span id="more-104"></span></p>
<p><strong>Note:</strong> All of the below are tests performed in Tridion 2009.</p>
<p><strong>Item naming.<br />
</strong>The following rules are present:</p>
<p>The CMS GUI will not let you enter more than 250 characters when naming (the item Title field) Publications, Folders, Components and Structure groups.  This also applied to the Structure Group “directory” field.</p>
<p>I found the page ‘Title’ field has a little quirk when naming as the GUI will allow an infinite number of characters however, if you enter more than 255, you will receive an error message like the one below:</p>
<p><a href="http://www.tridiondeveloper.com/wp-content/uploads/2010/03/tridion-long-page-title.gif"><img class="alignnone size-full wp-image-105" title="tridion-long-page-title" src="http://www.tridiondeveloper.com/wp-content/uploads/2010/03/tridion-long-page-title.gif" alt="" width="640" height="191" /></a></p>
<p>The page ‘Filename’ follows the normal convention of only allowing a user to enter 250 characters.</p>
<p>Tridion will allow most special characters, with the exception of “/” but I wouldn’t recommend ever using special characters as this will only lead to problems later in life J</p>
<p>If you simply must have special chars in your naming <a title="Tridion WebDav and special chars" href="http://www.tridiondeveloper.com/tridion-webdav-path-special">this post</a> may help you should you ever need to obtain such items using WebDav.</p>
<p><strong>WebDAV paths.<br />
</strong>The maximum length of a WedDAV path (on the system tested) is 300 characters.  Which means it is very easy to exceed this limit with a combination of long folder names and a deep folder structure.</p>
<p>The best advice is to keep all naming as short as possible and again avoid special characters.</p>
<p>Final note, I&#8217;ve only experimented with the items mentioned above, but I&#8217;m sure the same rules apply to items such as Page &amp; Component templates etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tridiondeveloper.com/some-notes-about-tridion-item-naming/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

