3

Below is the block of code that I'm having a problem with.

<ul class="description-tabs-menu--tabs-nav">
    @foreach(var fields in Component.Fields.product_tabs){
      <li>
        <a href="#@fields.tab_target_name"
        @if(fields.IsFirst){
            class="active"
        }
        >
        @fields.tab_title
        <span class="tab-bg-left"></span>
        <span class="tab-bg-tip"></span>
        </a>
      </li>
    }
</ul>

When attempting to save the template in Tridion, I get the following error:

TemplateCompileException: CS1513: } expected

Line 599 Column 33: Write(fields.tab_target_name);

WriteLiteral("\"\n");

  • if(fields.IsFirst){ class="active" }WriteLiteral(" >\n ");

CS1001: Identifier expected

Line 600 Column 22: WriteLiteral("\"\n");

if(fields.IsFirst){ * class="active" }WriteLiteral(" >\n ");

Can someone point to a solution?

6

Try using the <text> wrapper around your statements, in order to help the parser identify them properly.

See https://stackoverflow.com/questions/5369540/razor-renderpartial-exception-expected

| improve this answer | |
4

I think you might be better to write that like this using a terniary operator

<a href="#@fields.tab_target_name" @(fields.IsFirst ? "class=\"active\"" : "")>

As Mihai points out the parser is struggling to identify what is code and what isn't. This should make it a little easier for it.

| improve this answer | |
  • Please mark this as the answer so it can help others. – Nuno Linhares Nov 1 '13 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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