1

I am trying to figure out how to only display the slider on the homepage so that it does not show in other page.

I am getting close but not sure what code I should write. Here is what I could think of but does not work..

{% if slider in homepage %}
    slider goes here...
{% endfor %}

I appreciate any suggestion to what the correct way of displaying content in specific page/section/entry ...

2

Have a look at the Sections and Entries article in the official Craft documentations. It explains how to set up sections and how to configure them to load a particular template if an entry’s URL is requested. https://craftcms.com/docs/sections-and-entries

Another important topic you should get yourself familiar with is how Craft’s routing mechanism works. https://craftcms.com/docs/routing

To configure a template for your homepage you could create a template in craft/templates/index.html and Craft will use it for homepage requests (routing case 4). Or you configure a section in such a way that the homepage’s URI matches one of the section entries’ URIs (routing case 6). Note that there’s also a special checkbox “This is for the homepage” available in the settings for single sections.

With a designated template for your homepage in place, you can now add your slider code snippet to it. In the case that this template is responsible for multiple entries, e.g., entries of a structure section, you could wrap it in a conditional to check against the entry’s ID for example.

{% if entry.id == 12 %}
    <!-- Slider code -->
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.