Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

Access $Link from a custom function


Reply

3 Posts   354 Views

Avatar
Josiah

31 October 2013 at 8:24am (Last edited: 31 October 2013 8:25am), Community Member, 7 Posts

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?

Avatar
Devlin

31 October 2013 at 9:26pm (Last edited: 31 October 2013 9:27pm), Community Member, 215 Posts

Link is a method. You need to use:

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

Avatar
Josiah

1 November 2013 at 6:15am Community Member, 7 Posts

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