Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » how to use relative paths for theme files

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1979 Views
  • davee
    Avatar
    Community Member
    3 Posts

    how to use relative paths for theme files Link to this post

    hey guys,

    this is very basic on linking to /theme files in templates.

    given i am using my own theme and including css:
    <link rel="stylesheet" href="themes/exampletheme/css/screen.css" type="text/css" media="screen" />

    the thing is though, the engine generates links with slashes at the end by default, i.e.:
    www.example.com/contact/

    and this obviously wouldn't work as the ultimate http request to css is assembled as following:
    www.example.com/contact/themes/exampletheme/css/screen.css
    while i need the query to point to www.example.com/themes/exampletheme/css/screen.css

    in other words this kind of relative path above ("themes/exampletheme/....") doesn't work unless i remove the end slash from the URL.

    there seems to be a workaround by using $BaseHref for all media files but i am sure there is another clean way. just by looking at the code used at silverstripe.com ;)

    i also don't want to hardcode anything as paths on devel server are different.

    how do you guys deal with this? have i missed something in the confuguration .htaccess?

    cheers,
    davee

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: how to use relative paths for theme files Link to this post

    Have you got the <% base_tag %> in your theme? This sets the <base> tag in your template to yoursite.com/ so every relative link on the page is taken from this.

  • davee
    Avatar
    Community Member
    3 Posts

    Re: how to use relative paths for theme files Link to this post

    many thanks Will, this was helpful!

    1979 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.