Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Auto Pop-up on homepage

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

Page: 1
Go to End
Author Topic: 1919 Views
  • Jay-Dee
    Avatar
    Community Member
    11 Posts

    Auto Pop-up on homepage Link to this post

    Hello, I hope someone can help me with this one.

    I am trying to add a temporary auto pop up window on my homepage, however pasting my .js script on the html editor doesn't seem to work.
    I have added my script to my Page.ss file but now my pop up window comes up everytime any page loads.

    Is there a way I can tell my pop up window to load only when my home page is loaded?

    Thank you in advance and Happy New Year everyone!

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Auto Pop-up on homepage Link to this post

    Wrap your js in a if Title==Home block (or whatever your homepage is called)

  • Jay-Dee
    Avatar
    Community Member
    11 Posts

    Re: Auto Pop-up on homepage Link to this post

    Hello Zenmonkey, thanks for your reply, unfortunately I'm not sure I understand. I don't know much about js =$
    Could you explain a bit more? thanks again.
    Jay

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Auto Pop-up on homepage Link to this post

    In you Page.ss Template you should wrap javascript in an if Block

    <% if Title==Home %>
    Script Goes Here
    <% end_if %>

    That way it will only load the script on a page whose title is Home

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Auto Pop-up on homepage Link to this post

    It would be much better to use the Class of the page in the if statement as then you will include it on all the pages of that type AND you will be able to have your users change the title of the page and it will still work.

    eg:

    <% if ClassName = HomePage %>
    <script type="text/javascript">
    alert('this is the home page');
    </script>
    <% end_if %>

    1919 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.