Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Access $Link from a custom function

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

Page: 1
Go to End
Author Topic: 343 Views
  • Josiah
    Avatar
    Community Member
    7 Posts

    Access $Link from a custom function Link to this post

    Hello, I'm building a one page site that is put together by pulling in other pages in the site on the home page. These other pages have custom styles that are managed through the CMS and I'm targeting them by placing a 'data-path="$Link"' attribute on each page's section in the home page template (example output: <section data-path="/portfolio/first-entry/">)

    I need to output a style block in my template that targets the data-path attribute to give that section custom styles. Here's the starter code I have for the function I'm calling into my template file:

       function CustomStyles() {
          $pages = Page::get();

          echo '<style type="text/css">';
          foreach($pages as $page) {
             echo '[data-path="' . $page->Link . '"]{}';
          }
          echo '</style>';
       }

    However, $page->Link doesn't output anything because there isn't a Link property in the $page array. How can I access the same $Link property in my custom function that is used in the templating engine?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Access $Link from a custom function Link to this post

    Link is a method. You need to use:

    $pages = Page::get();
    foreach($pages as $page) {
    echo $page->Link();
    }

  • Josiah
    Avatar
    Community Member
    7 Posts

    Re: Access $Link from a custom function Link to this post

    Duh. I don't know what I was thinking, lol. Thanks!

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