Skip to main content
Advanced: Custom Homepage Carousel

This documentation will help you add, remove & update slides, links and other items related to your custom homepage carousel.

Peter Bernardo avatar
Written by Peter Bernardo
Updated over 7 months ago

PLEASE NOTE: This is not the standard slider option. If you are looking for more information on updating your homepage slider, please check out this article.

By choosing the custom homepage Top Featured section you will be responsible for updating content via a code editor. This is a custom section - we have put together a step-by-step guide for updating the images and links, adding and removing slides, and other tips and tricks.


Background

To allow for responsive images, these slides are set up using img srcset. This allows you to choose an image for small, medium, and large screens.

The pre-defined screen sizes we have selected correspond with standard mobile, tablet, and desktop sizes. You are welcome to change, add or remove sizes and we will go into this in more detail below.


Setting Up Your Template

When you chose the custom slider option, you will be provided with a template for the code. You can also find this code at the bottom of this article.

The sample code has 3 slides. Each slide begins and ends with a snippet of code that looks like this:

<!-- SLIDE 1 BEGIN -->
...
<!-- SLIDE 1 END -->

To add a slide, copy the code beginning and ending with the above comments and paste that slide code in the order you'd like your slider to function. We recommend keeping your code up-to-date so as you copy and move slides, update the comments to reflect the number that slide is. Your future self will thank you!

This is what your code would look like for a homepage slider with 3 slides:

To remove a slide, follow the same pattern as adding a slide, just select the code for the slide you want to remove and delete.

<!-- SLIDE 3 BEGIN -->
...
<!-- SLIDE 3 END -->


Anatomy of Img Srcset

When using an img srcset, there must be a space at the beginning and end of the code string:

To define the sizes of your slides, the width of the image needs to be set in the code. You'll add the img url, then a space, then the image width. The image width is written as the pixel + w.

An image that is 2500 pixels wide would be declared as: 2500w

You can use whatever image sizes work for your audience. Just remember to update the widths to match the image size.


Adding Images

Once you have the number of slides set up, it's time to add in your images.

To begin, with the standard code, you will need 3 images with the dimensions below:
Small Images: 768x480px

Medium Images: 992x480px

Large Images: 2500x700px

Upload your images into the admin section of your site under Static Content > Novi Files.

Once uploaded, you can right-click on the image and click Info:

When you're ready for the URL, copy the URL.

In an img srcset, you can define a fallback image that will show if a user's browser does not support img srcsets. As of this article, 96.11% of browsers do support this code (Source). We recommend using the large image as your fallback image so that a user will get the best experience regardless of screen size.

The image under src="...XXX..." is your fallback. Following the steps above, paste in the URL for your large image here.

Next, find the image that precedes the " 2500w," and paste the large image url here. *Reminder to keep the space between the first " and the 2500w.

To update the medium image, find the url preceding the " 992w," and paste your medium sized image url there.

To update the small image, find the url preceding the " 768w," and paste your small sized image url there.

Great job, your images are in place!


Adding the Slide Link

Having this custom slider allows you to link to any area of your site. Once your images are in place, you can add in the URL of the location you'd like the slide to click through to.

Find the <a href="###"> and replace the ### with your URL.

To have the link open in a new tab, just add target="_blank"

<a href="###" target="_blank">


Adding the Slider to Your Homepage

You have your code ready to go, now what?

Background on Javascript Rendering

The slider code works with Javscript embedded in your site.

JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else. - Mozilla

The Javascript code snippet could consist of a single line when you add it to your site. Once it renders on the page, it could be 100s of lines of code after it runs.

Because of the way Javascript will render your code after you save the code on the site, certain steps will have to be taken to update your slider.

Adding Slider Javascript to Your Site

Novi will get your site set up with the needed Javascript in your Association Settings. If you would like to custom the slider, you can find the Javascript in Association Settings > Analytics/Scripts in the Body Script or Markup section

Custom Code:

<script type="text/javascript">
$('.hp-slider').on('init', function(event, slick){
var $items = slick.$dots.find('li');
$items.addClass('transparent-circle');
});
$(document).ready(function(){
$('.hp-slider').slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
infinite: true,
autoplay: true,
autoplaySpeed: 5000,
prevArrow: '<a href="#" class="slick-prev slick-arrow" style="display: block;"><span class="novicon novicon-arrow-left"></span></a>',
nextArrow: '<a href="#" class="slick-next slick-arrow" style="display: block;"><span class="novicon novicon-arrow-right"></span></a>',
});
});
</script>

The two main items you may want to customize are:


autoplay: true,
True will autoplay your slider and changing this to false will stop the automatic scroll and users will have to tab through the slides to view each.


autoplaySpeed: 5000,
Adjusting this number will adjust the speed of the slides.

The other code is set up to show 1 slide per slide. We highly recommend NOT changing this. The template code will not support changing this and you will be responsible for writing code that would fit with this new layout.

Adding the Slider Code

Once you have your code ready to go, head over to your site and click into Tools > Source Code of your slider region.

If there is existing code in that section, delete all code, save the region, and refresh your page to begin with a blank canvas to avoid the Javascript issues mentioned above.

In source code, paste your slider code and save. Refresh the page. Viewing the page as an admin will not give you the true view of the slider. To see how it functions, you can either log out or view it in an incognito window.

Congratulations! You have a custom slider on your homepage.


Template Code Resource

Custom Homepage Slider HTML Code:

Adjust the width of the gallery in the first line of code.

<div class="row" id="gallery" style="width: 560px; scroll-margin-top: 40px;">
<div class="hp-slider">
<!-- SLIDE 1 BEGIN -->
<div>

<a href="###">
<img srcset=" https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/1-hp-slider-large-2500x700.jpg 2500w, https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/1-hp-slider-medium-992x480.jpg 992w, https://assets-staging.noviams.com/novi-file-uploads/mafsi/graphics/test-slides/mafsi-test-slide-sm.jpg 768w " src="https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/1-hp-slider-large-2500x700.jpg" class="img-responsive">
</a>
</div>
<!-- SLIDE 1 END -->
<!-- SLIDE 2 BEGIN -->
<div>
<a href="###">
<img srcset=" https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/2-hp-slider-large-2500x700.jpg 2500w, https://assets-staging.noviams.com/novi-file-uploads/mafsi/graphics/test-slides/mafsi-test-slide-md.jpg 992w, https://assets-staging.noviams.com/novi-file-uploads/mafsi/graphics/test-slides/mafsi-test-slide-sm.jpg 768w " src="https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/2-hp-slider-large-2500x700.jpg" class="img-responsive">
</a>
</div>
<!-- SLIDE 2 END -->
<!-- SLIDE 3 BEGIN -->
<div>
<a href="###">
<img srcset=" https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/3-hp-slider-large-2500x700.jpg 2500w, https://assets-staging.noviams.com/novi-file-uploads/mafsi/graphics/test-slides/mafsi-test-slide-md.jpg 992w, https://assets-staging.noviams.com/novi-file-uploads/mafsi/graphics/test-slides/mafsi-test-slide-sm.jpg 768w " src="https://assets.noviams.com/novi-file-uploads/novihq/hp-slider-assets/3-hp-slider-large-2500x700.jpg" class="img-responsive">
</a>
</div>
<!-- SLIDE 3 END -->
</div>
</div>

Custom Homepage Slider Javascript Code:

<script type="text/javascript">
$('.hp-slider').on('init', function(event, slick){
var $items = slick.$dots.find('li');
$items.addClass('transparent-circle');
});
$(document).ready(function(){
$('.hp-slider').slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
infinite: true,
autoplay: true,
autoplaySpeed: 5000,
prevArrow: '<a href="#gallery" class="slick-prev slick-arrow" style="display: block;"><span class="novicon novicon-arrow-left"></span></a>',
nextArrow: '<a href="#gallery" class="slick-next slick-arrow" style="display: block;"><span class="novicon novicon-arrow-right"></span></a>',
});
});
</script>

Did this answer your question?