Custom backgrounds in main div

Permalink 1 user found helpful
I have a problem I can't figure out.

My site consists of different backgrounds in the main content area for each page.

How do I build this into an editable block?
Do I create a new page template for each page?

The text that the editor inputs will sit on top of a white box over the photograph.

Seehttp://new.iteams.org.nz/concrete5.4.1/...

trixiemay
View Replies:
jbx replied on at Permalink Reply
jbx
You could create a new page attribute of type Image. Then set that for each page to the relevant image you want as the background image. Then in your template where you create the div, you can add it as a background image.

Jon
SVijay replied on at Permalink Reply
SVijay
Hi,

You need to create a new page attribute as you want for instance lets use 'background'. To create the attribute visit the link -
http://www.concrete5.org/help/building_with_concrete5/developers/at...

and you can get the attribute (background image)
as

<?php  $dd=$c->getCollectionAttributeValue('background');?>
<body>
<div style="Background:url(<?php echo File::GetRelativePathFromID($dd->fID);?>) top center no-repeat; ">
trixiemay replied on at Permalink Reply
trixiemay
Excuse my lack of knowledge here but...

my current code for the main content is:

<?php
$a = new Area('Main Content');
$a->display($c);
?>

what is the full code then?

And I aim the background:url to each new image?
trixiemay replied on at Permalink Reply
trixiemay
I have made a directory in models/attributes/type/background but what file goes into this directory and what is the coding?
SVijay replied on at Permalink Reply
SVijay
Hi,

Copy concrete/models/types/image_file/controller.php and paste it in models/types/background/controller.php, then change the class name ImageFileAttributeTypeController as BackgroundAttributeTypeController

and create a xml file having a table (atbackground) with two field
1. avID
2. fID
in models/types/background/db.xml

Try it, Good luck !!!
trixiemay replied on at Permalink Reply
trixiemay
do I need to create a new table in mysql first? Or do the 2 ids exist already?

what is the coding for the xml file?
SVijay replied on at Permalink Reply
SVijay
<?xml version="1.0"?>
<schema version="0.3">
<table name="atBackground">
    <field name="avID" type="I" size="10">
      <KEY></KEY>
      <DEFAULT value="0"></DEFAULT>
      <UNSIGNED></UNSIGNED>
    </field>
    <field name="fID" type="I" ></field>
</table>
</schema>


For more details visit

http://www.concrete5.org/documentation/how-tos/creating-and-working...
BigBobbyD replied on at Permalink Reply
BigBobbyD
Create an image attribute with handle bkImg.

Then add that attribute to the page type so it shows up in the properties automatically (page types-> edit).

Then upload your background images to the file manager.

Then update your page type's code like this:
$bkg = $c->getAttribute('bkImg'); ?>
<div id="content"<?=($bkg ? ' style="background-image: url(' . $bkg->getURL() . ')"' : '');?>>
    <?php
    $a=new Area('Main Content');
    $a->display($c);
    ?>
</div>


Now you can go page->edit page->properties->custom attributes and select the background image from the file manager.

I'm using the php shorthand if / else.

Make sense?
okhayat replied on at Permalink Reply
okhayat
I usually use the collection (page) handle as an ID for the main DIV.
For example, If I use the code:
<div id="<?=$c->getCollectionHandle()?>">
<!-- main page content -->
</div>

Which would gives me an ID for login, register, about-us, .. etc and easy way to customize this area or even the whole page.
BigBobbyD replied on at Permalink Reply
BigBobbyD
Much cleaner than my inline style!