SSI improvement (devs pls read this)

Started by Rudolf, November 21, 2006, 11:57:27 AM

Previous topic - Next topic

Rudolf

In SSI you can set the theme, the layers, but there is no way to set the template. Right now if I set the $ssi_layers variable, it will try to load the above and below functions from the index.template.php file. I wanted to avoid this, having a separate template file for my custom website/application (built on the SMF system). But I can't do with the current SSI.php.
So I modified the SSI slightly to make it more flexible.
Here are the changes:
1.
I replaced

// Load the stuff like the menu bar, etc.
if (isset($ssi_layers))
{
$context['template_layers'] = $ssi_layers;
template_header();
}
else
setupThemeContext();

with

// Load the stuff like the menu bar, etc.
if (isset($ssi_layers))
{
$context['template_layers'] = $ssi_layers;
if (!empty($ssi_template)) loadTemplate($ssi_template);
else loadTemplate($ssi_layers[0],false);
if (!empty($ssi_sub_template)) $context['sub_template'] = $ssi_sub_template;
}
else
setupThemeContext();

2.

// This shuts down the SSI and shows the footer.
function ssi_shutdown()
{
if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
template_footer();
}

with

// This shuts down the SSI and shows the footer.
function ssi_shutdown()
{
global $ssi_layers;
if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
if (!isset($ssi_layers))
template_footer();
else obExit();
}




The result is a much more flexible SSI.php, that is retains it's previous features/qualities.
With these modifications you can do things like setting up the layers, then a template and even the sub_template if it's needed.
Example:
Code (php) Select

<?php
$ssi_layers 
= array('custom_layer');
$ssi_template 'custom_template';
$ssi_sub_template 'main';
require_once(
'SSI.php');

//do some processing... of arbitrary complexity

if ($some_condition == true)
$context['sub_template'] = 'custom_sub_template_one';
else
$context['sub_template'] = 'custom_sub_template_two';

ssi_shutdown();
?>

In this case it will load the file custom_template.template.php in the current theme's folder, inside with the template_custom_template_above, template_custom_template_below, template_main and all the template_custom_sub_template functions defined.

Hopefully, someone from the SMF team will give this a though. ::)
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Thantos

There is a setting for including other templates besides index when you load a theme.  In theme_info.xml its done as a common seperate list inside the <templates> tag.  Its stored in the themes table with ID_MEMBER = 0, ID_THEME set to the theme ID, and the variable of theme_templates.

For example the theme used by the site is stored in a file called Mainsite.template.php with the forum specific part stored in index.template.php.  So ours looks like "Mainsite,index", which then causes SMF to load Mainsite.template.php and index.template.php everytime that theme is loaded, regardless if it's coming from SSI or regular viewing.

A similar action can be done using theme_layers to get it to automatically include layer functions.

Rudolf

That's not exactly what I want.
I don't need to add another layer over the existing design.
I just need to use the same theme, but with a separate template file(s). Like a custom action would do.
Basically my 'application' is a small set of actions/subactions that do something. I can't just insert in the forum's index.php (creating custom actions), because it has to run in a separate place(path) from the forum, but using the forums members table and theme (but not the main layer - it has it's own standalone layer, that is not visible on the forum), permissions, etc.

I remembered that there's an smf_api out there too. I'll take a look at that one, maybe it's more appropriate.
If it's not I can still use my modified SSI, because it's performing very well for me. It really provides a whole lot more flexibility with extremely little extra work.

This thing with the theme_info.xml is not quite clear to me. It seems to work in one direction, and not the one I need.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Advertisement: