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

$ThemeDir not working as intended


Go to End


4 Posts   2191 Views

Avatar
Kimyeti

Community Member, 7 Posts

23 April 2016 at 10:45am

Edited: 24/04/2016 11:18am

Hello guys

My $ThemeDir variable isn't working as intended for some reason. The only way I can get it to work, is to put my overall project folder in the link, like so:

href="/project-base/$ThemeDir/css/style.css" />

I want it to be like this:

href="/$ThemeDir/css/style.css" />

Does anybody know how to resolve this? Thank you.

Avatar
Kimyeti

Community Member, 7 Posts

24 April 2016 at 12:14pm

I've googled for 3 hours straight without any luck.

$Themedir should start from the root folder in the project and then go into the theme directory, but mine starts all the way from htdocs.

I'm desperate for an answer at this point.

Avatar
eightythree

Community Member, 12 Posts

24 April 2016 at 10:00pm

Edited: 24/04/2016 10:03pm

Hi Kimyeti,
could you describe what you need to achieve? If you need to SS place your stylesheet in head section you should do something like this:

For example in your Page.php or in any specific page, in the Controller add:

    public function init()
    {
        parent::init();
        Requirements::css($this->ThemeDir().'/css/style.css');
    }

You could also try to add <% base_tag %> in your Page.ss head section.

Cheers,
Darek.

Avatar
Kimyeti

Community Member, 7 Posts

25 April 2016 at 7:15am

Edited: 25/04/2016 10:46am

Hi eightythree,

Thank you for your reply.

The function works, but it's sadly not what I'm trying to achieve. I'm building a "project-base" which is a foundation for all my other future projects. The problem is that I need $Themedir to link correctly to my themes folder (which is does not). I do have a <% base_tag %> in my Page.ss, but it doesn't work.

If I need to link to an image for example then I need to write it like this:

<img src="/project-base/$ThemeDir/img/test.jpg">

But the clients website might be called "Febis-Pizza" and therefore I have to correct every link in my theme to this:

<img src="/febis-pizza/$ThemeDir/img/test.jpg">

I just want it to be like this:

<img src="/$ThemeDir/img/test.jpg">

In the SilverStripe tutorial for beginners it works and I do not understand what I'm doing wrong:
http://www.silverstripe.org/learn/lessons/migrating-static-templates-into-your-theme

Thank you again