Developer forum

Forum » CMS - Standard features » razor template tags?

razor template tags?

Mikkel Toustrup Olsen
Reply

Hello,

I am working with razor in DW on a daily basis, and I wonder how to get the old <!--@DwTemplateTags--> in a razor template? :-)

I got this piece of code, which does some of the work, however I can't get the "deeper" fields when using the following:

<pre>@string.Join("\n", Values.Select(e => string.Format("{0}: {1}", e.Key, System.Web.HttpUtility.HtmlEncode(e.Value))).ToArray())</pre>

I would love to make it more efficient, e.g. to show Field Names, Values, etc. The code above gives me an overview, but not in the quite same manner, as the DwTemplateTags (depending on the location) it will show the available properties, values etc.

Any suggestions?

 

 

 

 

 

 

 


Replies

 
Thomas Schroll
Reply

Hi Mikkel

See this post: http://developer.dynamicweb-cms.com/forum/cms-standard-features/dwtemplatetags.aspx

Regards Thomas

 

 

 

 
Mikkel Toustrup Olsen
Reply

Hi Thomas,

Thanks for your quick reply! - Looks fine, however I havent integrated any of my code in Visual Studio(yet). 

Are you familiar on this matter, or do you know whats best practice? .. Untill now I have only worked via the administration tool + their own, and Notepad++ with FTP access, this is decent, however it would be awesome to have syntax highlighting autocompletion in Visual Studio as well :-)

Regards Mikkel

 

 

 

 
Thomas Schroll
Reply
This post has been marked as an answer

Hi Mikkel

I haven't tried to use the solution for Intellisence in Visual Studio mentioned in the post yet, but if you include

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using System;
@using System.Linq;
@using Dynamicweb.Rendering;

in the top of your template, include the debug file (< !--@Include(Debug.cshtml)-->) you can see a list of tags by writing @ShowValues() or @ShowLoopValues("Products","Products/AssociatedGroups") where you normally would have written your DwTemplateTags statement.

Regards Thomas

 

Votes for this answer: 1
 
Mikkel Toustrup Olsen
Reply

Hi Thomas,

Thank you so much, just what I needed! :-)

 

 

 

 
Mikkel Ricky
Reply

Notice that you have to change the string.Join stuff to use the right Values object depending on the context:

@foreach (var i in GetLoop("LoopName")) {
<pre>@string.Join("\n", i.Values.Select(e => string.Format("{0}: {1}", e.Key, System.Web.HttpUtility.HtmlEncode(e.Value))).ToArray())</pre>
}

Note "i.Values" is used to get the values on the loop variable rather than just "Values".

 

You must be logged in to post in the forum