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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Calling a Module directly into HomePage.ss


Go to End


6 Posts   2115 Views

Avatar
Mrfixer

Community Member, 49 Posts

6 July 2011 at 3:30am

I have Nivoslider module running lovely on my site but only as long as i go create a slider in CMS using the NivoSliderPage, not a problem apart from the fact that i would like not to have to go to http://www.mysite.com/nivosliderpage/ to see it, what i want to do is show the slider onto my HomePage.

I thought this might work:

In CMS create a new Nivoslider page and in Behavior have it not to show in Menus

and then

Copy the nivoslider .ss files from inside the nivoslider modules templates/Includes and templates/Layout folders and pop them into my themes templates/Includes and templates/Layout and use an include from my themes HomePage.ss to call the NivoSliderContainer.ss

But all i get is an empty div showing where the slider should be going, how can i get this to work short of ripping the code from the Modules NivoSliderPage.php file and integrating into my HomePage.php?

Regards

Avatar
Webdoc

Community Member, 349 Posts

6 July 2011 at 9:10am

Its easier to make your own pagetype for nivoslider and add your own code to HomePage.ss
HomePage.php under mysite/code

<?php
/**
* Defines the HomePage page type
*/
class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);

static $allowed_children = array('Slide');
}

class HomePage_Controller extends Page_Controller {

}

?>

Slide.php same place as HomePage.php

<?php
/**
* Defines the Slide page type
*/
class Slide extends Page {
static $db = array(
);
static $has_one = array(
'Photo' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new ImageField('Photo'), 'Content');
return $fields;
}
}

class Slide_Controller extends Page_Controller {

}

?>

And in your Layout/Homepage.ss add:

<div class="typography">
<div id="slider1" class="nivoSlider">
<% control AllChildren %>
<img src="$Photo.URL" alt="$Title" title="$Title">
<% end_control %>
</div>
</div>

also u can add fixed width to image if u wanna.

Avatar
Mrfixer

Community Member, 49 Posts

6 July 2011 at 7:51pm

Edited: 07/07/2011 1:08am

Hey WebDoc.. your a star, many, many thanks, i managed to get it working in about 2 minutes with the help of the code you supplied, there was one line staring me right in the face..

static $allowed_children = array('NivoSliderPage');

now that worked, but wouldnt let me save settings from the Slider Settings panel in the Module, but how you laid your code out finally helped me to knock up the NivoSliderPage.php caode into my existing HomePage.php file without having to allow children

again thanks..

Avatar
Webdoc

Community Member, 349 Posts

23 July 2011 at 5:26am

U welcome i am also not a pro but happy to help

Avatar
greenpea

Community Member, 19 Posts

18 September 2011 at 4:39pm

Hi, I've tried out this code using the latest trunk build for Nivo Slider module, using SilverStripe 2.4.5.

I can create a slide child underneath the homepage. The slide page type only lets me add one image. This means the slider appears as a static image.

How can I amend slide.php, or homepage.ss to display images as a slider?

Thanks

Avatar
Naren

Community Member, 21 Posts

19 September 2013 at 7:07am

Edited: 19/09/2013 7:04pm

Hi all,

I have installed silverstripe 3.0 and also nivo slider with this, it was installed successfully, on admin I can function it very well.

But I dont know how to use this on my home page. I used various code to installed but failed. Can any one suggest me the right way how to use this one.

My theme structure is template/page.ss and Layout/page.ss

I have created the Homepage.ss under the layout folder as well, But dont know how to call it on home page.

Please guide me how to show it on the homepage.

Thanks in advance.