Developer forum

Forum » Templates » Trouble using old translate tags in combination with razor

Trouble using old translate tags in combination with razor

Thomas Clausen
Reply

Hi, I'm having some trouble using the old translate tags in combination with razor in two scenarios.

Scenario 1

The following piece of code are from a productlist template:

59: @if (Pageview.Area.ID != 10) {
60:     <strong><!--@Translate(ProduktlisteProduktPris, "Pris fra", global)--></strong> @product.GetString("Ecom:Product.Price.PriceWithVATFormatted") <!--@Translate(MurstenProduktlisteProduktStk, "pr. stk.", global)-->
61: }

generates the following error:

Line 60: Identifier expected
Line 60: ; expected

and the outputted code looks like this:

59: @if (Pageview.Area.ID != 10) {
60: <strong>Pris fra</strong> @product.GetString("Ecom:Product.Price.PriceWithVATFormatted") pr. stk.
61: }

If I change "@if (Pageview.Area.ID != 10) {" to "<!--@If(Global:Area.ID != 10)-->" or if i delete the last "<!--@Translate()-->" tag in line 60 the page doesn't generate an error anymore.

Scenario 2

The following piece of code are from a product template:

638: @if (Pageview.Area.ID == 1) {
639:     <!--@Translate(ReferencegalleriTekstDel1, "Kom ud og se", global)--> <span>@GetString("Ecom:Product.Number")</span><br />
640:     <a href="mailto:john@email.dk?subject=@GetString("Ecom:Product.Number") - forespørgsel på produkt&amp;body=Jeg ønsker at få tilsendt materiale omkring ovenstående produkt."><!--@Translate(ReferencegalleriLink, "Spørg på referenceadresser", global)--></a>
641: }

generates the following error:

Line 639: ; expected
Line 639: ; expected

and the outputted code looks like this:

638: @if (Pageview.Area.ID != 10) {
639: Kom ud og se <span>@GetString("Ecom:Product.Number")</span><br />
640: <a href="mailto:john@email.dk?subject=@GetString("Ecom:Product.Number") - forespørgsel på produkt&amp;body=Jeg ønsker at få tilsendt materiale omkring ovenstående produkt.">Spørg på referenceadresser</a>
641: }

Again if I change "@if (Pageview.Area.ID == 1) {" to "<!--@If(Global:Area.ID == 1)-->" or if I delete the the "<!--@Translate()-->" tag in line 639 the page doesn't generate an error anymore.

 

The solution is running version 8.4.1.9

What am I missing/not seeing - Any suggestions?


Replies

 
Morten Bengtson
Reply

Have you tried using the Razor helper functions instead of the old tags?

http://developer.dynamicweb.com/forum/templates/razor@translate-in-8-4-1-15.aspx#Reply37534

 
Mikkel Ricky
Reply
This post has been marked as an answer

When Razor compiles a template it has to determine what is code and what is content (static text). The start of a code block is signaled by the @ character and content is typically wrapped in some tag (to tell if from code).

In your first example

59: @if (Pageview.Area.ID != 10) {
60: <strong>Pris fra</strong> @product.GetString("Ecom:Product.Price.PriceWithVATFormatted") pr. stk.
61: }

line 59 is code, line 60 starts with some content (<strong>…</strong>) followed by some code (@product.GetString(…)) and some more code ( pr. stk.). The problem is that Razor thinks that "pr. stk." is code, but it's not (we can easily tell, but Razor cannot).

We have to tell Razor that "pr. stk." is content, and this can be done by

  • wrapping it in <text>…</text>: <text>pr. stk.</text> (Razor will remove <text> and </text>)
  • adding @: in front of it: @: pr. stk.

but the easiest way to handle this is probably to wrap the entire line:

59: @if (Pageview.Area.ID != 10) {
60: <span class="price-info"><strong>Pris fra</strong> @product.GetString("Ecom:Product.Price.PriceWithVATFormatted") pr. stk.</span>
61: }

Take a look at ASP.NET MVC 3: Razor’s @: and <text> syntax for more details on how to handle static content in Razor using <text/> and @:

Best regards,
Mikkel

 

Votes for this answer: 1

 

You must be logged in to post in the forum