Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Concatenate variables

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

Page: 1
Go to End
Author Topic: 1857 Views
  • CraigB
    Avatar
    Community Member
    7 Posts

    Concatenate variables Link to this post

    I am trying to Take a custom field for a page and use it as a part of a link to some pre generated documentation.
    The link has the following format:
    /products/$ProductCode Release/output/index.htm
    I want to be able to remove the space after $ProductCode.

    The result I want to endup with is as follows:
    /products/PWRelease/output/index.htm

    Where $ProductCode is "PW"

    Thanks

    Craig

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Concatenate variables Link to this post

    Yup just go:

    /products/{$ProductCode}Release/output/index.htm

  • CraigB
    Avatar
    Community Member
    7 Posts

    Re: Concatenate variables Link to this post

    Thanks for that.

    You wouldn't also no how to use page variables in a function for the page?
    ie.    function DocURL() {
          return '/products/'.$ProductCode.'Release/output/index.htm';
       }

    This doesn't seem to work, the Product code is never populated.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Concatenate variables Link to this post

    Yea you cant use template variables in the php code but you can do:

    function DocURL() {
    $product = $this->ProductCode;
    return '/products/'.$product.'Release/output/index.htm';
    }

  • CraigB
    Avatar
    Community Member
    7 Posts

    Re: Concatenate variables Link to this post

    Thanks again.

    That seems like a bit of a limitation but at least there is a way to get it to work.

    Cheers

    1857 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.