6

I would like to split the email address across two separate lines, ie left of the @ and right of the @inclusive, i am using Dreamweaver templates. (Tridion Version 2009), Thank you

0

2 Answers 2

12

Jamie has included some great suggestions. All of which I recommend over this one, but most people don't realize that there is limited string manipiulation possible using JScript functions (i.e. substring and indexOf) within DWT TBBs. So this is possible:

@@"[email protected]".substring(0,("[email protected]").indexOf("@"))@@<br/>
@@"[email protected]".substring(("[email protected]").indexOf("@"))@@

Of course you can use a field value instead of the whole string, but this shows the point. I think this is pretty ugly, and would really suggest creating a Function Source, but in a pinch, this would work for you.

2
  • thank you, i can get this to work as detailed using a string
    – user610
    Commented Nov 1, 2013 at 11:24
  • 2
    @user610 if this answer solved your problem please consider marking it as the accepted answer (even if it is ugly!) Commented Nov 3, 2013 at 8:00
9

Depending on what the use case is, there are several approaches, for example, do you want to apply this behaviour to all the email addresses in the output? is it in a specific situation?

If it is the first case (apply to all email addresses) you can achieve that by implementing a C# TBB that "finds" all the email addresses (with a regular expression for example) and replace them with the "splitted" version of them.

If it is for a specific "field", you could pass the field name as a parameter using a parameter schema in the very same TBB and only replace the email address that matches the field you passed by as a parameter.

Yet another option would be to implement a Dreamweaver Function something like 'SplitEmailAddress(email)' that will do the job for you. Then you should be able to do something like @@SplitEmailAddress(${Component.Fields.email})@@.

However you need to take into account what is a "new line" for you. It could be a \n or \r or a html 'br' element, etc...

5
  • i am struggling over creating a function, i am going round in circles with the Tridiion documentation, my tbb source contains
    – user610
    Commented Nov 1, 2013 at 11:35
  • <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Text.RegularExpressions" %> /// Fragment Functions <%! private string getEmailLeft(string strValue) { string strEmailLeft =""; strEmailLeft = strValue.Substring(0, strValue.LastIndexOf("@")); return strEmailLeft; } %>
    – user610
    Commented Nov 1, 2013 at 11:36
  • and i get error message in the template builder
    – user610
    Commented Nov 1, 2013 at 11:36
  • Variable 'GetEmailLeft' has not been declared eval code: Line 1 - Error: Variable 'GetEmailLeft' has not been declared
    – user610
    Commented Nov 1, 2013 at 11:37
  • To create a custom function, you'll need to create an assembly with a class implementing the IFunctionSource interface and method(s) with the TemplateCallable attribute. There's information about the general approach here: sdllivecontent.sdl.com/LiveContent/content/en-US/… and you should be able to find the details in the API documentation for the above mentioned classes. Commented Nov 1, 2013 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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