Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Accessing variables within a <control>

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2327 Views
  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Accessing variables within a <control> Link to this post

    Hi !

    I'm currently working on a dual-language website. I tied the word-list to the homepage so the user can maintain this list themselves. Accessing theses variables in the template works like a charm, except when I'm in a control block.

    Here's an example (I'm in the homepage template):

    <% control LatestNews %>
       <div class="case_news">
        <h2>$MetaTitle</h2>
        $MetaDescription
        $Read_more
       </div>
    <% end_control %>

    SS cannot access the $Read_more variable now (since it's linked to the Homepage).

    If I place $Read_more _outside_ of the control block , it will work.

    Anyone knows how i can access the variable from within the control ?

    Thanks !

  • Andy
    Avatar
    230 Posts

    Re: Accessing variables within a <control> Link to this post

    $Link will do what you want, you don't need to create $Read_more.

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Accessing variables within a <control> Link to this post

    Thanks for your reply.

    $Link produces a correct hyperlink to the item, but that is not my problem. I can't seem to figure out how to switch languages. "Read more" should read "lees meer" in Dutch (so the $Read_more string only contains text , no URL or anything.

  • Andy
    Avatar
    230 Posts

    Re: Accessing variables within a <control> Link to this post

    Oh, I get ya, sorry! Try $Parent.Read_more

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Accessing variables within a <control> Link to this post

    Thanks, but nope. Can't seem to get to that variable (or to a function defined in the homepage-controller).

  • Alex S
    Avatar
    Community Member
    30 Posts

    Re: Accessing variables within a <control> Link to this post

    Having the same issue, no joy so far...

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Accessing variables within a <control> Link to this post

    Alex :

    try :
    $Top.variable

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