Jump to:

23460 Posts in 18907 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Set a Background Image

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2779 Views
  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Set a Background Image Link to this post

    In the Page.php file - this is all working

    public static $has_one = array(
        "BackgroundImage" => "Image"
    );

    $fields->addFieldToTab("Root.Content.OptionalHeaderImage", new ImageField("BackgroundImage", "Background Image:"));

    ---

    In my template, I would like only the image path, but the system return this...

    background-image:url(<img src="/assets/Backgrounds/blue-star/bg-body.jpg" alt="blue star" />);

    How do I get just the path and file only?

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Set a Background Image Link to this post

    Got it.

    $BackgroundImage.URL

    Add the .URL onto your control and it returns only the path.

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Set a Background Image Link to this post

    On another issue, can I refine this even further?

    What I need now is just the file name only?

    /assets/Folder/filename.jpg

    I need the "filename.jpg"

    Any ideas?

    Thank you,
    Steve Nyhof

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Set a Background Image Link to this post

    $BackgroundImage.Filename?

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Set a Background Image Link to this post

    Nope! It would be nice if it were that easy.

    All it did was remove the first /

    $name.URL = /assets/

    $name.Filename = assets/

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Set a Background Image Link to this post

    Sorry Steve, I should verify before posting. Try: $BackgroundImage.Name

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Set a Background Image Link to this post

    Yes!!, you are the man!

    Thank you, now onto the next steps with javascript.

    Steve

    PS. where do I find these table fields in the database?

  • steve_nyhof
    Avatar
    Community Member
    224 Posts

    Re: Set a Background Image Link to this post

    Any ideas where tosearch to put a javascript path together?

    formbgimagename = "form-bg-blue.png";
    formbgimagesmall = "style="+"background-image:url(assets/Forms/Small/"+formbgimagename+")";

    This doesn't work.

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