I have component layout in DWT. I need to add a small server side code there? How do we do that?
-
I have seen few snippets are added with <% %>. If I want to print the year how will I do that?– vidsCommented 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?– vidsCommented Apr 1, 2015 at 9:39
-
1you want to render the year at publishing time or when the code runs on the webserver?– Saurabh GangwarCommented Apr 1, 2015 at 10:03
-
I want to run the code on webserver– vidsCommented Apr 1, 2015 at 13:23
-
1Vids, 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.– Alvin ReyesCommented Apr 1, 2015 at 20:45
4 Answers
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
-
Can you show me how to create custom function in DWT? Or can you give me any reference?– vidsCommented Apr 1, 2015 at 9:43
-
1take a look at jarnohenneman.com/2014/04/Dreamweaver-templating Commented Apr 1, 2015 at 10:00
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
Adding to @Andrey Marchuk answer, you can also use Razor templates as explained here.
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.