Overriding profile pages within a theme package

Permalink 1 user found helpful
For the need of customizing the profile single pages, I'd like to know how to override the profile pages within a theme package?
Rendering them within a themes' view.php is fine by adding them to config/site_theme_path.php, but I need to customize the html within the single pages.

Thanks in advance, greets

synlag
 
5fly replied on at Permalink Reply
5fly
Hi,

Should be relatively simple... you just need to create the single pages in your package and then on the install or update of your package controller you will need to change the package references on the originals by using something like:

//update some core package to be associated with this package to allow overrides within the package
    private function overrideSinglePagePackage($pkg){
        $db = Loader::db();
        $p = Page::getByPath('/login');
        $cID = $p->getCollectionID();
        $db->execute('update Pages set pkgID = ? where cID = ?', array($pkg->pkgID, $cID));
        $p = Page::getByPath('/download_file');
        $cID = $p->getCollectionID();
        $db->execute('update Pages set pkgID = ? where cID = ?', array($pkg->pkgID, $cID));
        $p = Page::getByPath('/register');
        $cID = $p->getCollectionID();
        $db->execute('update Pages set pkgID = ? where cID = ?', array($pkg->pkgID, $cID));
        $p = Page::getByPath('/profile');
        $cID = $p->getCollectionID();
        $db->execute('update Pages set pkgID = ? where cID = ?', array($pkg->pkgID, $cID));


You'll need to reverse this manually on the uninstall method of your package as well...

Hope that helps!
synlag replied on at Permalink Reply
synlag
Thanks for your reply. As described at "Customizing a Single Page's Appearance" here
http://www.concrete5.org/documentation/developers/pages/single-page...

It says that single pages can be overriden by a theme by including a file with the same name within your theme directory, in this case the theme lives in a package directory and overriding single pages that directly live in single pages folder works fine. e.g. login, register, maintance mode, user error, update, etc.

But it does not respect the profile/ folder.
I couldnt figure out so far, where concrete5 does look for that, so I might be able to include the files in the profile folder.

Any idea?

Thanks in advance.
Mainio replied on at Permalink Reply
Mainio
I think the theme-level overrides only work with the exact file names of those views. So e.g. if you want to override profile/edit.php, you'll need to place a file in the theme's root folder named "edit.php".

Of course, this makes it difficult if you need to override multiple views that use the "edit.php" but if that becomes a problem, you could also do some additional checks in that file to decide which view it is trying to display.
synlag replied on at Permalink Reply
synlag
@Mainio thanks for your reply, but at least this wont work for view.php as this file needs to exist in a theme folder.
If I could figure out, which controller is responsible for checking these overrides and rendering the single page files in a package theme, I could override this in the package to respect the profile folder and files within.
Mainio replied on at Permalink Reply
Mainio
For the main-level view, you'll need to use that view's handle, i.e. the "view.php" override you'll need to do for the profile-section in the theme-level would be "profile.php".

If you just check the "cHandle" column from the Collections table, you're able to determine what the file should be named before the ".php" extension.

The theme-loading / single page content loading process is not handled by a controller, it's handled by the view library.
5fly replied on at Permalink Reply
5fly
Just so that I'm 100% what your asking here:

You don't want to override the single pages themselves... Just apply a view.php from a theme that lives in a package? :)
synlag replied on at Permalink Reply
synlag
Well, I do, because I want to customize the html that lives in the profile folder :)
5fly replied on at Permalink Reply
5fly
In that case - if you want to override the HTML and page layout from within a package... your going to need to create the package/single_pages/profile/edit.php (taking a copy from the core first obviously) and then do the DB updates as above...

Unless anyone else has a better way?

We've had to do this quite a few times... I can give you a full how-to if needs be!
synlag replied on at Permalink Reply
synlag
Thanks a lot for your help, this seems to what I will be ending up with.
What I was expecting is, that putting the profile folder within my package/themes/theme_name folder like the other files described in my first reply would work. This might be a great way to just override them, when this particular theme is used.
A how-to would be awesome :)

Greets
5fly replied on at Permalink Reply
5fly
No problem - Ill add it to my list of how-tos to-do! ;)
synlag replied on at Permalink Reply
synlag
Haha,

we just wrote a similar how-to xD
Figured it out on the weekend, check it out :)

http://www.concrete5.org/documentation/how-tos/developers/overridin...

Greets
5fly replied on at Permalink Reply
5fly
sorry - forgot to mention you might also want to copy the /concrete/elements/profile/sidebar to your package as well....
synlag replied on at Permalink Reply
synlag
Thanks, already done ;)
synlag replied on at Permalink Reply
synlag
The $themeFilename for the profile/view.php is set to profile.php, so adding this to the package_name/themes/theme_name folder works and lets me override the profile pages within the theme.
Same for profile/edit.php, profile/avatar.php, profile/messages.php and profile/friends.php.
Finally works :)