Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » How to print Variable as part of string larger string

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1060 Views
  • bmc38119
    Avatar
    Community Member
    45 Posts

    How to print Variable as part of string larger string Link to this post

    I need to add a mouseover event to navigation links and want to have the $URLSegment as part of the unique name. However, it appears that I cannot do this b/c the variable is inserted in the middle of a larger string.

    see example below:

    <a href="$Link" onMouseOver='document.nav_$URLSegment.src=nav_$URLSegment_over.src;' onMouseOut='document.nav_$URLSegment.src=nav_$URLSegment_off.src;'><img src="/$ThemeDir/images/nav-$URLSegment-off.jpg" name="nav_$URLSegment" style="display:block;border:none;padding-left:5px;float:right;" /></a>

    other than creating functions to handle creating the entire string, is there another method to be able to tell the template where to start or end the variable name?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: How to print Variable as part of string larger string Link to this post

    You can 'escape' the variable by using { }. Eg SomeStringWith{$AVar}InTheMiddle

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: How to print Variable as part of string larger string Link to this post

    thank you. exactly what i needed.

    1060 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.