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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Including HTML in Footer Only on HomePage


Go to End


8 Posts   777 Views

Avatar
ColWebDev

Community Member, 4 Posts

29 April 2015 at 4:27am

Edited: 29/04/2015 4:28am

I'm new to SilverStripe, so please bear with me :-)

I want to include a link in the footer.ss ONLY when the visitor is viewing the home page. I've tried various options like

<% if ClassName = HomePage %>
 ... my html code here ... 
<% end_if %>

but it still either shows (or doesn't) on every page.

How do I show something only on the home page from WITHIN the footer? TIA!

Avatar
helenclarko

Community Member, 166 Posts

29 April 2015 at 9:39am

Hi ColWebDev,

You could try the following in your footer.ss file:

<% if URLSegment = home %>
... html code here ... 
<% end_if %>

-helenclarko

Avatar
ColWebDev

Community Member, 4 Posts

29 April 2015 at 2:39pm

Edited: 29/04/2015 2:52pm

helenclarko, thanks for the reply, but I'm afraid that doesn't work either. It shows on the home page that way, but also continues to show on every other page.

Could it be a caching/some other issue? (I HAVE been flushing after each change, but...) Any other ideas what I could be doing wrong? Or another way to accomplish what I'm trying to do?

Avatar
Lexandclo

Community Member, 55 Posts

2 May 2015 at 2:02am

Try

<% if InSection(home) %>
.....text here  ..
<% else %>
<% end_if %>

That should work

Avatar
ColWebDev

Community Member, 4 Posts

12 May 2015 at 2:32am

hmmm...that didn't work either. I came into this site for a client after it was set up, so I'm going to assume there's something odd about the way it's set up and keep poking around. Thanks for the feedback, though! if anyone knows anything else I could try, I'm all ears. ;-)

Avatar
Pyromanik

Community Member, 419 Posts

12 May 2015 at 9:23pm

Edited: 12/05/2015 9:34pm

If <% if $URLSegment == 'home' %> shows on every page, then you've either got a single page website... or you've the parser is confusing what is and isn't a string.

It's also important to ensure you're editing the correct template (see the first few tutorials for more info on this).

Avatar
ColWebDev

Community Member, 4 Posts

13 May 2015 at 2:03am

Pyromanik, thanks for the troubleshooting direction. I know it's not a single page site b/c I can set the various templates (home page, internal page, etc) from the backend. I also know I"m editing the correct footer file since I DO see any changes I make on the live site.

So let's say for argument's sake the parser is confused. As I stated initially, I'm new to SS (but not to coding/CMSs in general). Is there some way for me to "dirty" code it - maybe put a variable on the homepage somewhere that doesn't show, and then check if that variable is set in the footer? Something like:
if ($homeCheck == "abcde") { show homepage code }, where $homeCheck is just some random variable I set up?

Avatar
Pyromanik

Community Member, 419 Posts

13 May 2015 at 8:42pm

<% if $ClassName == 'HomePage' %> - 'clean'
<% if ClassName = home %> - not so 'clean'. It's rare, but the parser can confuse strings and variables (not randomly, but it can happen) - $ and '' make it specific.

I think it's more likely you're confusing scope, possibly through structuring your site in some confusing manner.