2

I have written a DWT which is creating an XML as below:-

<?xml version="1.0" encoding="utf-8"?><episodes><episode>
<episode_id>EPS_7208_7205_56</episode_id>
<title>Episode 56</title>
<media_links>
  <media_link>
    <asset_id></asset_id>
    <media_filepath>\Entertainment\TV Shows\TV Show 56.mp4</media_filepath>
    <media_type>mp4</media_type>
  </media_link>
</media_links></episode><episode><episode_id>EPS_7208_7205_57</episode_id>
<title>Episode 2</title>
<media_links>
  <media_link>
    <asset_id>Asset_EPS_56</asset_id>
    <media_filepath>\Entertainment\TV Shows\TV Show 1.mp4</media_filepath>
    <media_type>mp4</media_type>
  </media_link>
</media_links></episode><episode><episode_id>EPS_7208_7205_58</episode_id>
<title>Episode 2</title>
<media_links>
  <media_link>
    <asset_id>Asset_EPS_57</asset_id>
    <media_filepath>\Entertainment\TV Shows\TV Show 1.mp4</media_filepath>
    <media_type>mp4</media_type>
  </media_link>
</media_links></episode></episodes>

DWT Code:-

<?xml version="1.0" encoding="utf-8"?><episodes><!-- TemplateBeginRepeat name="episodes" --><episode>   <episode_id>EPS_@@GetIdFromTcmUri(Component.ID)@@_@@episode_number@@</episode_id>
@@SetVariable('EpisodeNumber', episode_number)@@
<title>@@title@@</title>
<media_links>
  <!-- TemplateBeginRepeat name="media_links" -->
  <media_link>
    <asset_id>Asset_EPS_@@GetVariable('EpisodeNumber')@@</asset_id>
    <media_filepath>@@media_filepath@@</media_filepath>
    <media_type>@@media_type@@</media_type>
  </media_link>
  <!-- TemplateEndRepeat -->
</media_links></episode><!-- TemplateEndRepeat --></episodes>

I calling template callable methods:-

/// <summary>
    /// 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.
    /// </summary>
    /// <param name="variableName">Name of the varialbet</param>
    /// <param name="value">Value of the variable</param>
    [TemplateCallable()]
    public string SetVariable(string variableName, string value)
    {
        //Remove the old variable and set the new variable
        m_engine.PublishingContext.RenderContext.ContextVariables.Remove(variableName);
        m_engine.PublishingContext.RenderContext.ContextVariables.Add(variableName, value);

        return String.Empty;
    }

    /// <summary>
    /// Gets a variable from the publishing context.
    /// </summary>
    /// <param name="variableName">Name of the variable</param>
    [TemplateCallable()]
    public string GetVariable(string variableName)
    {
        //Get the variable
        try
        {
            return m_engine.PublishingContext.RenderContext.ContextVariables[variableName].ToString();
        }
        catch
        {
            return String.Empty;
        }
    }

IN the asset_id node I want the value of episode number which was set initially as soon as episodes loop started. But the value which I am expecting for asset_id node of an episode is getting written in the asset_id node of episode which is next to it in xml. Can you please tell where I am wrong?

1
  • Where is the value of episode_number coming from exactly, the way I read your DWT TBB it seems to be in the package, so you could simply use @@episode_number@@ but I might be missing something here? Perhaps you need to look at my answer here for options on how to use multiple value parameters in the package? Sep 4 '13 at 14:10
4

I am confused as to why you cannot directly use the field @@episode_number@@ rather than using built-in function in your DWT. If it is in the component it should be accessible. Otherwise I would recommend posting your component xml to give a better idea. And, indeed as @Eric mentions the DWT is evaluated inside to outside, so the innermost repeating region is evaluated before evaluating outer repeat regions or any references.

<?xml version="1.0" encoding="utf-8"?><episodes><!-- TemplateBeginRepeat name="episodes" --><episode>   <episode_id>EPS_@@GetIdFromTcmUri(Component.ID)@@_@@episode_number@@</episode_id>
<title>@@title@@</title>
<media_links>
  <!-- TemplateBeginRepeat name="media_links" -->
  <media_link>
    <asset_id>Asset_EPS_@@episode_number@@</asset_id>
    <media_filepath>@@media_filepath@@</media_filepath>
    <media_type>@@media_type@@</media_type>
  </media_link>
  <!-- TemplateEndRepeat -->
</media_links></episode><!-- TemplateEndRepeat --></episodes>

Component xml

<Content xmlns="uuid:01cee2f6-035c-4ced-b225-abde4ceded5e">
    <episodes>
        <episode_number>5</episode_number>
        <media_links>
            <Link>Link5.1</Link>
        </media_links>
        <media_links>
            <Link>Link5.2</Link>
        </media_links>
    </episodes>
    <episodes>
        <episode_number>6</episode_number>
            <media_links>
            <Link>Link6.1</Link>
        </media_links>
    </episodes>
</Content>

Series DWTBB

<?xml version="1.0" encoding="utf-8"?>
<episodes>
<!-- TemplateBeginRepeat name="episodes" -->
<episode>
    <episode_id>EPS__@@episode_number@@</episode_id>
    <title>@@title@@</title>
    <media_links>
        <!-- TemplateBeginRepeat name="media_links" -->
        <media_link>
            <asset_id>Asset_EPS_@@episode_number@@</asset_id>
            <media_filepath>@@Link@@</media_filepath>
            <media_type>@@FieldPath@@</media_type>
        </media_link>
        <!-- TemplateEndRepeat -->
    </media_links>
</episode>
<!-- TemplateEndRepeat -->
</episodes>
6
  • In episode schema there episode_number field. media_links is an embeddable schema with two fields media_filepath and media_type. While publishing I need a unique asset_id for this media link. that is why I want to prefix Asset_EPS before the episode_mumber in asset_id node. when I am looping for media_link field I am not able to fetch the episode_number directly by using @@episode_number@@ or @@Fields.episode_number@@ or @@Field.episode_number@@
    – AlokBhatt
    Sep 5 '13 at 3:57
  • In my attempt I am using Series schema with episode as multivalued embedded schema with medialink multivalued embedded schema. ** Component <Content xmlns="uuid:01cee2f6-035c-4ced-b225-abde4ceded5e"> <episodes> <episode_number>5</episode_number> <media_links> <Link>Link5.1</Link> </media_links> <media_links> <Link>Link5.2</Link> </media_links> </episodes> <episodes> <episode_number>6</episode_number> <media_links> <Link>Link6.1</Link> </media_links> </episodes> </Content>
    – Likhan
    Sep 5 '13 at 5:33
  • I am doing exactly same what your are doing here. Are you able to fetch episode_number directly.
    – AlokBhatt
    Sep 5 '13 at 5:42
  • 1
    Updated the answer with the component xml and dwt i tried on my system. Which seems to work. Can you share the component Xml?
    – Likhan
    Sep 5 '13 at 5:43
  • Hey Likhan. Thanks for your answer. Your suggestion resolved my problem. But problem is also with SetVariable and GetVariable method behaviours. the behaviour of these methods in my code is making these methods of no use.
    – AlokBhatt
    Sep 5 '13 at 6:04
3

DWTs are executed from inside to outside, it means that the repeat section and GetVariable are executed before SetVariable so that your episode number is not set yet.

Try to set the variable in the repeat section (i know it would be extra processing), it will ensure the variable is available when you execute GetVariable

Other option would be of course to move the logic to C# TBBs and create a Dummy Array including the episode titles include the episode number

1
  • Hey Eric, This behaviour of SetVariable and GetVariable methods making them of no use.
    – AlokBhatt
    Sep 5 '13 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.