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   396 Views

Avatar
Josiah

Community Member, 7 Posts

31 October 2013 at 8:24am

Edited: 31/10/2013 8:25am

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

Community Member, 217 Posts

31 October 2013 at 9:26pm

Edited: 31/10/2013 9:27pm

Link is a method. You need to use:

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

Avatar
Josiah

Community Member, 7 Posts

1 November 2013 at 6:15am

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