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.

All other Modules

Discuss all other Modules here.

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

Calling a Module directly into HomePage.ss


Reply

6 Posts   1490 Views

Avatar
Mrfixer

6 July 2011 at 3:30am Community Member, 49 Posts

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

6 July 2011 at 9:10am Community Member, 332 Posts

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

6 July 2011 at 7:51pm (Last edited: 7 July 2011 1:08am), Community Member, 49 Posts

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

23 July 2011 at 5:26am Community Member, 332 Posts

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

Avatar
greenpea

18 September 2011 at 4:39pm Community Member, 19 Posts

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

19 September 2013 at 7:07am (Last edited: 19 September 2013 7:04pm), Community Member, 21 Posts

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.