loadPartialTemplate function Please?

Started by SoLoGHoST, November 08, 2015, 05:21:30 AM

Previous topic - Next topic

nend

Been playing around with a similar idea with function hijacking. When a function is called passed vars can be modified or the function replaced by another with integration hooks. This could be applied to themes, however it's no magic bullet.

It isn't SMF will not change, it is change takes time.

SoLoGHoST

I'm not trying to get into a debate on whether or not I am comparing SMF to Wordpress, because I simply am not trying to do this.  I only provided an example of how Wordpress handles hooking functions.  I can see that it is pointless, this conversation, yes.  I might as well talk a different language.  Cheers :)

SoLoGHoST

#42
@nend, yes, I showed an example of this in earlier post with the integrate_prepare_display_context hook.  The thing I would like to see here, is ability to change HTML, not so much variables.  Although variable changing would be nice also, but that is already pretty much possible, since $context is the main variable for templates and can be modified mostly in Source files.  Basically, I just would like to be able to hook in my own partial templates, like partial HTML inside of the template, without editing the template.

I suppose it might help if SMF did something like this inside of their templates:


if ( ! function_exists( 'template_main' ) )
{
    function template_main() {
        // All template code in here...
    }
}


Than maybe we could override these functions individually with our own...  I think if they were to do this with more functions, we can hook our own in another template to overwrite parts of HTML.  Possibly a start on this?  Haven't worked with SMF in awhile, so a bit out of practice here, but if they loosened up their templates a bit and used that code where it can actually work, than perhaps it might be a great start to editing Themes that are already installed...

Thoughts?

Suki

Thats already possible. You can overwrite functions in PHP.  Theres also the layer system, you can CRUD any template and subtemplate layers.

And no, the way wordpress does stuff cannot be applied to SMF, WP and SMF are two different things.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Kindred

WordPress. I've been working with it for years and I absolutely hate using it for anything other than a very basic blog site. I actually agree with you regarding Drupal but not for the same reasons. Drupal has issues burying div inside div inside div so that modifying any css in their template is nearly impossible.

And arantor hit the nail on the head... WordPress is not good just because people use it...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

SoLoGHoST

#45
Quote from: Suki on August 19, 2016, 09:49:01 AM
Thats already possible. You can overwrite functions in PHP.  Theres also the layer system, you can CRUD any template and subtemplate layers.

Can you provide minor examples of this perhaps?  If you are referring to override_function, than that requires APD PECL extension. Maybe this is 1 of the reasons why SMF should go OOP?  Than we can use Interface to accommodate this better.

live627

Complete template override? Easy. I have some code I wrote several years ago to do this very thing:

function template_init()
{
add_integration_function('integrate_menu_buttons', 'fixSubTemplates', false);
}

function fixSubTemplates()
{
global $context;

$new_sub_template = empty($context['sub_template']) ? 'main_override' : $context['sub_template'] . '_override';

if (is_callable('template_' . $new_sub_template))
$context['sub_template'] = $new_sub_template;
}


The hook should be late enough in the runtime where you know the templates will have been already loaded, otherwise the overrides won't work.

nend

@live627, nice, I didn't think of that.

Here's what I wrote a week or two ago.

$smcFunc += array(
'ufunc' => function ($func, $vars = null, $array = false)
{
// Allow hooking into functions to rewrite vars or send the data to another function instead.
call_integration_hook('integrate_before_func_'.$func, array(&$func,&$vars));
if (!empty($func))
$return = call_user_func_array($func, is_array($vars) && $array == true ? $vars : array(&$vars));
if (!empty($return)) {
// allow modifications of return data.
call_integration_hook('integrate_after_func_'.$func, array(&$return));
return $return;
} else
return false;
},
'load' => function ($path, $file, $type = 'generic')
{
// File hijacking, good for when you want to replace source files with others.
// Types source, theme, lang, generic
call_integration_hook('integrate_require_'.$type.'_'.$file, array(&$file));
require_once ($path.$file);
}
);

SoLoGHoST

Nice, but adding it to an integration called integrate_menu_buttons?  There should be built-in functionality for this that is obvious, not sneaky hacks.

In any case, thanks for sharing guys, but I feel like Suki was referring to overidding a function via PHP only, and I'd like to see an example of that without using the APD PECL extension.

Suki

Quote from: SoLoGHoST on August 20, 2016, 01:42:21 AM
Nice, but adding it to an integration called integrate_menu_buttons?  There should be built-in functionality for this that is obvious, not sneaky hacks.


Thats redundant. A hook is just a place in "space" and runtime, its name its just an indicator of where the hook is called, not its purpose.  A hook can be used in any purpose you want.

Quote from: SoLoGHoST on August 20, 2016, 01:42:21 AM
In any case, thanks for sharing guys, but I feel like Suki was referring to overidding a function via PHP only, and I'd like to see an example of that without using the APD PECL extension.

Nope.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

live627

QuoteNice, but adding it to an integration called integrate_menu_buttons?
Yeah. And  it works.

Hacks never look pretty.

SoLoGHoST

Ok, thanks again all for your attention on this topic.  I'm very lucky to have the attention that you folks give here.  Such great talented coders that have a huge impact on SMF and it's development makes me very proud to have the replies on this topic from such great minded individuals.  Thanks and I look forward to what SMF becomes in the future.  :)

Advertisement: