News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

add_integration_function help

Started by MobileCS, February 12, 2025, 11:55:23 PM

Previous topic - Next topic

MobileCS

I'm trying to create a mod that will allow me to add content to $context['html_headers'] using hooks only.

My function is loaded in package-info.xml via :

<require-file name="Subs-Example.php" destination="$sourcedir" />
<hook hook="integrate_pre_include" file="$sourcedir/Subs-Example.php" function="add_header_stuff" />


Example.php
function add_header_stuff() {
    ....
    ....
    $context['html_headers'] .= $extra_data;
}
add_integration_function('???', 'add_header stuff', false);

What hook do I need to call in the add_integration_function() to make this work?


Diego Andrés

In 2.1 if you're going to load files or scripts you don't need html_headers.
You can use ‎integrate_pre_javascript_output and/or integrate_pre_css_output and then use the desired functions such as loadCSSFile or loadJavaScriptFile; or their respective inline functions.

SMF Tricks - Free & Premium Responsive Themes for SMF.

MobileCS

I'm not loading any files or scripts, I just need to add schema data to the <head></head> section.

The integrate_load_theme sort of works, but my function needs access to:

global $context, $txt, $scripturl, $modSettings, $boardurl;
It doesn't appear that hook gives me access to those, even those I have that line above inside my function.

Sesquipedalian

Quote from: MobileCS on February 13, 2025, 09:51:25 PMI'm not loading any files or scripts, I just need to add schema data to the <head></head> section.

The integrate_load_theme sort of works, but my function needs access to:

global $context, $txt, $scripturl, $modSettings, $boardurl;
It doesn't appear that hook gives me access to those, even those I have that line above inside my function.

It does. Since we don't know what the code in your function looks like, we can't comment further, but if you correctly declared those global variables at the start of your function, then the problem lies elsewhere.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

MobileCS

Just for a simple test, this is what I'm doing :

package-info.xml
...
...
<install for="2.1.4">
    <require-file name="Subs-Test.php" destination="$sourcedir" />
    <hook hook="integrate_load_theme" file="$sourcedir/Subs-Test.php" function="add_header_data" />
</install>
...
...

Subs-Test.php
function add_header_data() {
    global $context, $txt, $scripturl, $modSettings, $boardurl;
   
    $site_name = $context['forum_name'];
    $context['html_headers'] .= '<meta property="og:site_name" content="' . $site_name . '">';
}

It always shows content="" - the only thing that appears to be working is $scripturl

live627

SMF 2.1 allready does this

    <title>add_integration_function help</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta property="og:site_name" content="Simple Machines Community Forum">
    <meta property="og:title" content="add_integration_function help">
    <meta property="og:url" content="https://www.simplemachines.org/community/index.php?topic=590955.0">
    <meta property="og:description" content="add_integration_function help">
    <meta name="description" content="add_integration_function help">
    <meta name="theme-color" content="#557EA0">

Advertisement: