Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » inline css in template

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

Page: 1
Go to End
Author Topic: 2061 Views
  • markus85
    Avatar
    Community Member
    12 Posts

    inline css in template Link to this post

    Hi out there,

    maybe some one can help me.

    I want to add an random image to my header. These images are in the image-folder from my template.

    How can I access these files from the template --> Page.ss ?

    I just inserted some lines of code and it works fine but there is no image I think the relative path is wrong.
    So my question is:

    How can I access these files from the Page.ss ?
    Is there another possibility to get inline-css code into a template ?

    Greets

  • ramu
    Avatar
    Community Member
    15 Posts

    Re: inline css in template Link to this post

    Hi markus85,

    Please find the sample code to get the image from the folder

    function getAllFiles($directory='') {
          $result = array();
          $folder = Director::baseFolder() . '/'.$directory.'thumb/';
          $thumbdir = $directory.'thumb/';
        $handle = opendir($folder);
          $directorylist='';
           while ($datei = readdir($handle))
           {
              if (($datei != '.') && ($datei != '..') && ($datei != 'Thumbs.db'))
              {
                 $file = $thumbdir.$datei;
                 $abpath = $folder.$datei;
                 if (!is_dir($file)) {
                      $result[filemtime($abpath)] = $file;
                 }
              }
           }
           closedir($handle);
           foreach ($result as $val) {
              $filename = basename($val);
               $directorylist .= '<div><a href="'.$directory.$filename.'"><img src="'.$val.'" /></a></div>';
           }
           return $directorylist;
    }

  • banal
    Avatar
    Community Member
    901 Posts

    Re: inline css in template Link to this post

    Inline css in the template should be fine. If you want the path to the template folder, you can either enter the full path (relative to the site-base) or use the $ThemeDir variable in your template. Something like this:

    <style type="text/css">
    #MyHeader {
    background: url($ThemeDir/images/myHeader.jpg) no-repeat left top;
    }
    </style>

  • markus85
    Avatar
    Community Member
    12 Posts

    Re: inline css in template Link to this post

    thx for the answers.
    Didn´t know about that variable $ThemeDir.

    Works fine

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