Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » <% require %> custom CSS

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

Page: 1 2
Go to End
Author Topic: 4328 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    Re: <% require %> custom CSS Link to this post

    am I missing something here....doesn't the customCSS requirement just stick it in the <head> section of the page anyway??

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: <% require %> custom CSS Link to this post

    Yeah, I'm not sure what the problem is. Requirements will always put them in the right place.

    Adding requirements from the template is a relatively new feature. You could add a feature request for more power in the customCSS method, at http://open.silverstripe.com, or just do the old way (adding it to your page class).

  • chrisdarl
    Avatar
    Community Member
    33 Posts

    Re: <% require %> custom CSS Link to this post

    Because the <% require %> feature isn't allowing me to reference a variable inside it?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: <% require %> custom CSS Link to this post

    function init() {

    parent::init();

    Requirements::customCSS( "background : url(" . $this->LeftBlock2_Image()->URL . ");");

    }

    Thats off the top of my head so the syntax may be slightly different but you get the idea.

  • chrisdarl
    Avatar
    Community Member
    33 Posts

    Re: <% require %> custom CSS Link to this post

    Thanks Aram for all your help - it's really appreciated!

    I'll give that a go and post the code I succeed with (well hopefully)

  • chrisdarl
    Avatar
    Community Member
    33 Posts

    Re: <% require %> custom CSS Link to this post

    I got this working by using Arams suggestion. I put the following code inside the init function of my Page_Controller

    if($this->TopImage()->ID) {
       Requirements::customCSS(".top-image { background : url(".$this->TopImage()->URL.") no-repeat !important; height : ".$this->TopImage()->getHeight()."px !important; }");
    }

    Thanks for helping Aram and Hamish

    4328 Views
Page: 1 2
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.