Developer forum

Forum » Templates » How to use Dynamicweb Format Tag Extention?

How to use Dynamicweb Format Tag Extention?

Sten Hougaard
Reply

Hi,

I wonder how to use the Format extension in Dynamicweb? I have had no luck using it...

I guess that it would take some string in the format which Microsoft uses when formatting content?

How would I say use it to format a price to Danish standard price formatting?

Like go from 91902.95 to 91.902,95 

Say that the custom tag which gives the raw value looks like this:

Namespace.Product.GrossPriceInCurrentCurrecy

How should I then use say the formatdouble tag?

Namespace.Product.GrossPriceInCurrentCurrecy.FormatDouble(**¿what to write here?**)

 

 

Med venlig hilsen/Best regards,

 

Sten Hougaard

Webudvikler

 

A: København/Aarhus . W: www.1stweb.dk

 

 

 

 

 

 

 

 


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

The argument to FormatDouble (and FormatInteger and Format) is a composite format string that can be understood by the String.Format method. See Composite Formatting for details.

Some examples you can use

@Namespace.Product.GrossPriceInCurrentCurrecy.FormatDouble({0:C})
@Namespace.Product.GrossPriceInCurrentCurrecy.FormatDouble({0:C1})
@Namespace.Product.GrossPriceInCurrentCurrecy.FormatDouble({0:F})
@Namespace.Product.GrossPriceInCurrentCurrecy.FormatDouble({0:F1})




 

 

 

 

 

Votes for this answer: 1
 
Sten Hougaard
Reply

Thank you Mikkel.

Is this theori or have you tried it in real life? It is making no difference here at the soloution I am working on!

...GrossPriceInCurrentCurrecy.FormatDouble("{0:F}") -> 9285
...GrossPriceInCurrentCurrecy.FormatDouble({0:F}) -> 9285

And that applies for all the examples you have submitted...

/Sten

 

 

 

 

 
Mikkel Ricky
Reply

Of course I have tried it. Which version of Dynamicweb are you using?

 
Sten Hougaard
Reply
Version: 8.2.2.2 (Fri, 05 Apr 2013 14:06) - Standard - hnext.lan  
 
Mikkel Ricky
Reply

The tag extensions documentation states that you have to run Dynamicweb 8.2.3.0 or newer to use the FormatDouble extension tag.

 

 
Martin Gammelholm
Reply

Hi Mikkel,

I'm also having difficulties using the double tag extension.

The solution is running version 8.2.3.8:
http://www.proterapi.dk/kopi-af-produktertest/traeningscykler/monark-traeningscykel-927e.aspx

I'm trying to format the following tag like so 1.000,00:
http://screencast.com/t/x3TFUnbM9i

But nothing happens. Been trying all sorts of combinations.

The field is a customfield, so I figured, maybe it doesn't work with customfields, but it's the same deal with the standard price tag.

The customfield is set to "Decimal number" in backend, so it's actually being formatted correctly when you look at the value in eCom, but the output from the tag throws the format away.
http://screencast.com/t/SFG6D0nrCM1u

The template is PT_Product2013.html

 

BR
Martin

 
Mikkel Ricky
Reply

You have to write

.FormatInteger({0:C})

I have added a couple of examples to the documentation.

Best regards,
Mikkel

 
Martin Gammelholm
Reply

Hi Mikkel,

Thanks for the quick reply.

I can see that you've edited the template, but nothing have changed in frontend:
http://screencast.com/t/82iGXWRJI0

I've tried with both Format and FormatInteger, and different sorts of combinations.
I just want to format the output like so: 11.000

 

BR
Martin

 
Sten Hougaard
Reply

I have a simular issue. Trying to format a date on an item:

<!--@ItemPublisher:Item.Publish_Date.Format({0:MM/dd/yy H:mm:ss zzz})-->

11/22/2000 returns: 11/22/2000

I am on 8.4.1.15.

If I wrap the format param in quotes I get this .NET error, perhaps it help you debugging:

System.FormatException: Input string was not in a correct format.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(String format, Object arg0)
   at Dynamicweb.Rendering.Template.ProcessMethods(String tagName, String value, String methods)
   at Dynamicweb.Rendering.Template.GetTagValue(Match match)
   at Dynamicweb.Rendering.Template.ReplaceTag(Match match)
   at System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
   at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator, Int32 count, Int32 startat)
   at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
   at Dynamicweb.Rendering.Template.ReplaceTags(String tmpOutput)
   at Dynamicweb.Rendering.Template.Output()
   at Dynamicweb.Rendering.Loop.Commit(String parentName, Int32 parentLoopIndex, Int32 loopCounter)
   at Dynamicweb.Rendering.Template.CommitLoop()
   at Dynamicweb.Content.Items.Rendering.Renderer.RenderItems(IEnumerable`1 items, ItemListSettings settings)
   at Dynamicweb.Modules.ItemPublisher.Frontend.List()
   at Dynamicweb.Modules.ItemPublisher.Frontend.GetContent()
   at Dynamicweb.Frontend.Content.getModule(DataRow& ParagraphRow)

 


Med venlig hilsen/Best regards,

Sten Hougaard
Webudvikler

E: sho@1stweb.dk
M: 29850818
A: København/Aarhus . W: www.1stweb.dk
@: netsi1964

 
Nicolai Høeg Pedersen
Reply

Hi Sten

The tag values are in strings - so the date you pass to .Format is already a string and will therefore not react on a date format string...

That is why we have FormatDouble and FormatInteger - so we convert the template value from string to the right type before applying the format on the value.

So, I just added a FormatDate string extension method. But it is 'dangerous' to use because changing dates from string to date can go wrong. So remember to use a RFC date format or something.

That said, can you not use one of the date formats already provided by the template engine? http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Date/time-tag-extensions.aspx

 
Nicolai Høeg Pedersen
Reply

@Martin

({0:C}) is formatting a currency and needs a double or an integer to work. That would give you something like "Kr. 3,00" - just tried it like this:

<!--@Ecom:Order.OrderLines.TotalProductQuantity.FormatInteger({0:C})-->

You need to use another string

<!--@Ecom:Order.OrderLines.TotalProductQuantity.FormatInteger({0:F0})-->

where F0 controls the number of decimals, i.e. F1 = 3,0, F2 = 3,00.

Since you are formatting a price, you should use FormatDouble instead:

.....Value.Clean.FormatDouble({0:C})

 
Sten Hougaard
Reply

Hi Nicolai,

Thank you for your reply. I guess we would love to get a "HTML5 Microformat" extention to the time-tag-extensions (TTE).

Like: http://microformats.org/wiki/abbr-datetime-pattern

So that we can format:

<time datetime="2012-08-26 20:09-0700">
  8:09pm on August 26th, 2012
</time>

I actually have tried to use the TTE, but also run into values not formated with prefixed zero (like 8 is not 08)

/Sten

 
Martin Gammelholm
Reply

Hi Nicolai,

Nothing happens I'm affraid:
http://www.proterapi.dk/kopi-af-produktertest/traeningscykler/monark-traeningscykel-927e.aspx

Should this be working together with customfields even?

My tag looks like this now:
<!--@Ecom:Product:Field.PTStykPris1.Value.Clean.FormatDouble({0:C})-->

Screen:
http://screencast.com/t/82iGXWRJI0

 

BR
Martin

 
Nicolai Høeg Pedersen
Reply

@Sten

You can use a long variaty of formats (http://microformats.org/wiki/value-class-pattern#Date_and_time_values), i.e. the sortable offset which is available in Dynamicweb:

<!--@ Ecom:Order.Date.SortableOffset-->: 2014-06-26T13:03:09+02:00

@Martin

proterapi.dk is running on 8.2 and the tag extension methods FormatDouble and FormatInteger requires 8.3... (Build date after 20/8-2013)

Nicolai

 
Martin Gammelholm
Reply

Hi Nicolai,

 

Does say 8.2.3.0 in the documentation though:
http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Tag-extensions.aspx

Proterapi is running 8.2.3.8.

 

BR
Martin

 
Nicolai Høeg Pedersen
Reply

Yes, Tag extensions in general was introduced in 8.2.3 - FormatDouble and FormatInteger are from 8.3.

Documentation updated.

 

You must be logged in to post in the forum