Customizing SMF > SMF Coding Discussion
Adding a sidebar without template edits
IchBin™:
In order to add your sidebar without theme edits, you'll need to use the layers in SMF theme system. Here's a brief explanation that I got from Bloc at one time which helped me understand them.
--- Quote --- - Say you just added a new action and do all sorts of stuff inside Yourpage.php, and now gonna render the template. First you add a layer by adding a name to the variable $context['template_layers'].this HAS to be done BEFORE calling the template(which you nromally doa t the ery end of Yourpage.php, or a function within it)
$context['template_layers'][] = 'yourpage';
Then SMF will now try execute "template_yourpage_above" and "template_yourapge_below". So you just stick whatever you want into these two, much like "template_body_above". Like a sandwich lol.
Those two functions needs to be loaded in though, and thats where loadtemplate('yourpage'); comes in: You stick the two functions into a file called "yourpage_template.php" and put it into Themes/default. Its important that naming is consistant, otherwise SMF won't find it.
Done.
.....
Now, often you like do subtemplates for example, for a specific part of your page/mod. That would then be executed BETWEEN the function "template_yourpage_above" and "template_yourpage_below", and needs to be named like this:
$context['sub_template'] = 'yourpage_mysub';
Then SMF will try render things like this:
- template_yourpage_above()
- template_yourpage_mysub()
- template_yourpage_below()
So you just put all those functions into yourpage.template.php. You can add more by just setting the correct subtemplate + making sure the function exist in the template.
--- End quote ---
Doctor Deejay:
Thanks for your reply :) So, I can create a sidebar by putting the normal content in a specified width? Like this:
- Width, float, etc
- Sidebar
- Close the above
- Width and float
- Regular content
- Close the above
IchBin™:
Not sure I understand your list of explanation, but yes you can put any column and specify the width of course.
Labradoodle-360:
You could also use... $context['insert_after_template'] .= ''; which would allow you to do the same thing.
Doctor Deejay:
Thank you both, going to try out that tomorrow :D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version