Skip to main content

how to get substring in soy template?

I have soy template in which I want only 28 character if the length is more than 30 characters? how to get that?

   {if $attributes.subAccountNumber.length < 30}
   {$attributes.subAccountNumber}  
    {else}
    {$attributes.subAccountNumber.substring(0,28)}                                                                                                              
    {/if}

But on compilation it throws exception,

Exception in thread "main" com.google.template.soy.base.SoySyntaxException: In file war/js/Application/Reports/ViewTemplates/ReportsViewTemplate.soy:518, template acti.workflow.reports.transcriptCard: Not all code is in Soy V2 syntax (found tag {$attributes.subAccountNumber.substring(0,28)} not in Soy V2 syntax).
at com.google.template.soy.base.SoySyntaxException.createWithoutMetaInfo(SoySyntaxException.java:52)
at com.google.template.soy.soytree.SoySyntaxExceptionUtils.createWithNode(SoySyntaxExceptionUtils.java:48)
at com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(AssertSyntaxVersionV2Visitor.java:105)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitPrintNode(AbstractSoyNodeVisitor.java:221)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:85)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:55)
at com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:59)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(AbstractSoyNodeVisitor.java:126)
at com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(AssertSyntaxVersionV2Visitor.java:112)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitIfElseNode(AbstractSoyNodeVisitor.java:253)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:95)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:55)

Solved

I don't believe that Closure templates allow you to call JavaScript functions on the objects. As much of an inconvenience as it is, you'll have evaluate {$attributes.subAccountNumber} before you pass it to the template (in Java or JS). I believe this is due to it remaining as a templating system and not a JS library.


Comments

Popular posts from this blog

Tableau and MariaDB connectivity issues

I am trying to connect Tableau Desktop (tried version 9.2 and 2018.1 both) with MariaDB (Server version: 10.0.20-MariaDB-log MariaDB Server). I am selecting MySQL in the list of data source servers in Tableau. The connection is getting established but 1. Databases are not visible 2. Custom SQL is not available Data refresh 3. Live or extract options are not visible What am I doing wrong? Solved Almost all the posts mention that connecting to MySQL data source works perfectly fine if we need to connect to MariaDB. There are, however, few differences. Follow these steps in case of similar problem: In connecting to the data source, select Other Databases (ODBC) Select Driver and choose MySQL ODBC 5.3 Unicode Driver Provide connection details like server IP, port, username and password that is used to connect with MariaDB That's it.