Hi there,
I really need help here before I go mad!
On the left hand side of all my templates I want to display a small box with a random client comment.
STEP 1)
In the CMS I have set up a "Holder" page with the URL/ID "client-feedback-items". (This is a blank page)
The children of this holder use a page type which has three custom fields:
Quote (text)
Name (text)
Organisation (text)
I am using the following naming convention for each new child page: clientFeedback1, clientFeedback2, clientFeedback3 and so on.
The pages themselves are never displayed within the site structure (they are hidden from menu and search). Instead I want to display elements from them on most other pages (randomly picking one)
I have an include, called by most pages in my site, named RandomQuote.ss
This contains the following code at the moment:
<div id="quote">
<% control Page(clientFeedback1) %>
<p class="words">"$Quote"</p><p class="person">$Name, <br/>$Organisation</p>
<% end_control %>
</div>
This allows me to display the content of the first quote page.
If I changed it to <% control Page(clientFeedback2) %> it would display the contents of that page instead.
(This works so far...)
STEP 2) this is where I am coming undone!!!
I need to know how many child pages there are in the holder "client-feedback-items", then i need to pick a random number between 1 and the 'child count' of "client-feedback-items". I then have to return this value to the template page in order to display the random quote.
Here's how I've tried to go about it:
In the Page.php controller I added the following code: (idea was to count child pages then return a random number)
function pickRandomQuote() {
$upperLimit = $Children(client-feedback-items).Count; //count number of child items
$random = rand(1, $upperLimit);
$theRandomQuote = 'clientFeedback'.$random;
return $this->$theRandomQuote;
}
then I changed the code in RandomQuote.ss as follows:
<div id="quote">
<% control Page($pickRandomQuote) %>
<p class="words">"$Quote"</p><p class="person">$Name, <br/>$Organisation</p>
<% end_control %>
</div>
(Replacing the hard-coded ID with the variable/funtion: $pickRandomQuote)
For reason(s) that I don't understand it doesn't work. It's maybe something a bit obvious and stupid that I'm just not seeing (well, it's getting late now and I'm losing the will to go on!)
I also tried using:
$upperLimit = $Children.Count(client-feedback-items); //count number of child items
and just a hard-coded one:
$random = rand(1, 4);
to test if it worked or if the count code was wrong, but it still didn't work.
Any help would be much appreciated. I know I'm waffling on a bit, but its hard to explain it all!!!
Thanks,
L