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 /

Random Function not working ss File


Reply


1037 Views

Avatar
ramu

Community Member, 15 Posts

15 November 2009 at 2:14am

Hi

Please find the my query below. i am using to get random metakeywords from the page

Myfiles:

/code/Page.php
/code/Homepage.php
themes/<theme>/Page.ss <- my Layout template
themes/<theme>/Layout/Homepage.ss <- my template

MetaKeywords: "youtube clone, video scripting, video software

Page.php

...
class Page_Controller extends ContentController {
   function RandomMetaKeywords()
   {
      if ($this->MetaKeywords)
         $HomePageValue = $this;
      else   
         $HomePageValue = DataObject::get_one('HomePage', '', '', '', '');
         
      $keywords = explode(', ',$HomePageValue->MetaKeywords);
      $rand_keys = array_rand($keywords,1);
      $retKey = $keywords[$rand_keys];
      unset($keywords);
      return ($retKey);
   }
}

Page.ss

...
<div>$Title</div>
$RandomMetaKeywords
$RandomMetaKeywords

<div>$Layout</div>

HomePage.ss

...
<div>$Title</div>
$RandomMetaKeywords
$RandomMetaKeywords

above my code, In Page.ss file successfully get the random values while function call but in layout file ie (HomePage.ss) it will get same value for all the function call.

output of Page.ss

youtube clone
video scripting

output of HomePage.ss

youtube clone
youtube clone

Please help to clear this issue.

Regards,
thisIsRam