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

Set a Background Image


Go to End


12 Posts   5428 Views

Avatar
steve_nyhof

Community Member, 224 Posts

27 December 2009 at 7:25am

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?

Avatar
steve_nyhof

Community Member, 224 Posts

27 December 2009 at 7:30am

Got it.

$BackgroundImage.URL

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

Avatar
steve_nyhof

Community Member, 224 Posts

24 March 2010 at 6:09am

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

Avatar
Juanitou

Community Member, 323 Posts

24 March 2010 at 9:19am

$BackgroundImage.Filename?

Avatar
steve_nyhof

Community Member, 224 Posts

24 March 2010 at 10:12am

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

All it did was remove the first /

$name.URL = /assets/

$name.Filename = assets/

Avatar
Juanitou

Community Member, 323 Posts

24 March 2010 at 11:25am

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

Avatar
steve_nyhof

Community Member, 224 Posts

24 March 2010 at 2:06pm

Edited: 24/03/2010 2:06pm

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?

Avatar
steve_nyhof

Community Member, 224 Posts

24 March 2010 at 3:44pm

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.

Go to Top