0

I have component layout in DWT. I need to add a small server side code there? How do we do that?

5
  • I have seen few snippets are added with <% %>. If I want to print the year how will I do that?
    – vids
    Commented Apr 1, 2015 at 9:38
  • If I add <%= DateTime.Now.Year.ToString() %> it shows the same code in the browser. Any idea how do we update that?
    – vids
    Commented Apr 1, 2015 at 9:39
  • 1
    you want to render the year at publishing time or when the code runs on the webserver? Commented Apr 1, 2015 at 10:03
  • I want to run the code on webserver
    – vids
    Commented Apr 1, 2015 at 13:23
  • 1
    Vids, thanks for asking on Tridion Stack Exchange. I suspect the downvote on this question is for it being a little vague on what time of code you wanted to output and what seems like a lack of research. Most will ask, "what did you try?" for anything you might ask on a technical forum. I think your question can be improved if you add the expected output and behavior from your comments into the question along with any issues you had trying this. Commented Apr 1, 2015 at 20:45

4 Answers 4

3

The main reason for using modular templates is to split design from code. You should either add custom function which you will be able to call directly from DWT or create a C# template which will push variable into the package and you will then display it in DWT

2
2

In addition to what Andrey suggested, you may want to use the Dreamweaver Get Extension which is a community extension in which you can write your methods in C# and call these methods directly from the DWT template. The details of DWT Extensions can be found here: Dreamweaver Get Extension DGX

2

Adding to @Andrey Marchuk answer, you can also use Razor templates as explained here.

1

As you want the code to run on the web server, then it's a standard templating task. How the code should look will depend on your web application server. So for example - if you are running ASP.NET, you might output code that looks like this:

<%
  // whatever you want to do... 
%>

or perhaps

<script runat="server">
  // some code
</script>

Occasionally, you'll find that you have to escape some syntax that is significant in your templating language, but Dreamweaver syntax doesn't usually collide with server scripting languages. If you can't use ${}, then use @@ instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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