Using $context['template_layers'][] in Hook, breaks the jump to on boardindex

Started by Pipke, February 24, 2015, 08:15:19 AM

Previous topic - Next topic

Pipke

Maybe found a bug or script stopping thingy, it breaks/stops the 'jump to =>' dropdown box (javascript) script on boardindex using 'integrate_load_theme' and then in the function using $context['template_layers'][].

see my code and screenshot (the orange Loading..box), quick mod package is included in the attachement.

$hooks = array(
    'integrate_pre_include' => '$sourcedir/RecentForumTopics.php',
    'integrate_load_theme' => 'rft_load_themes',
    );

foreach ($hooks as $hook => $function)
    add_integration_function($hook, $function);


RecentForumTopics.php:

function rft_load_themes()
{

    global $context, $modSettings;
   
    loadTemplate('RecentForumTopics');

    $context['template_layers'][] = 'rft';
}


Template:

function template_rft_above()
{
    echo'I write here some text in the above template';
}

function template_rft_below()
{
    echo'I write here some text in the below template';
}


anyone know how to fix it, or are you (the development team) aware of this?

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Pipke

edit, as i cannot edit my own topic???

the title says boardindex but has to be when your inside board or topic ofcourse as the boardindex hasnt any Jump To box on the template.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Check your source code (the HTML source code), your template layer code is probably breaking the resultant HTML.

Or try to put your sentence inside a div:

echo'
<div class="windowbg">I write here some text in the below template</div>';

Do note the new line after echo '  it helps to keep the resultant HTML properly indented.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Quote from: Suki on February 24, 2015, 09:28:34 AM
Check your source code (the HTML source code), your template layer code is probably breaking the resultant HTML.

Or try to put your sentence inside a div:

echo'
<div class="windowbg">I write here some text in the below template</div>';

Do note the new line after echo '  it helps to keep the resultant HTML properly indented.

Sorry to tell you Suki, changed the template file to this , bug still exist.

function template_rft_above()
{
    echo'
        <div class="windowbg">I write here some text in the above template</div>';
}

function template_rft_below()
{
    echo'
        <div class="windowbg">I write here some text in the below template</div>';
}

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Just tested the package you attached on both 2.1 and 2.0 and it shows normally for me.

Do you have any other mods installed on test board?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Quote from: Suki on February 24, 2015, 09:49:09 AM
Just tested the package you attached on both 2.1 and 2.0 and it shows normally for me.

Do you have any other mods installed on test board?

Nope no other mods or file changes.
bug still exist, i did new clean smf install? if i remove the $context['template_layers'] line the jump to box works agian, weird stuff going on here, maybe a chmod thingy?
btw did you clicked the arrow drop down box Suki?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

So, what is exactly th bug?  I cannot see anything.

The dropdown still works? if you mean that the drop down doesn't redirect you then it probably is because your browser doesn't like Synchronous XMLHttpRequest calls

Check your console log, there should be an error similar to this one:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

The bug is that it doesnt show the boards where you want to 'JUMP TO' in the jump to dropbox, it hangs on the board where your in/are atm and shows then on top the loading.. message.
in screenshot it shows now general board + board + board 2 and board 3, as it should be, but not when installed the code $context['template_layers'][] in Hook.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Ah yes, I do see it now... well, this is going to be awkward to fix on 2.0. Happens on 2.1 but should be easy to fix there.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Suki

OK, after some research and remembering that SMF can print out XML data :P, it turns out this isn't a bug.

It turns out that SMF calls your templates even when printing XML data so the resulting XML data is corrupted by whatever HTML you are printing and that results in the JS that retrieves the cats and boards to be borked.

To fix this add a check for xml on your function:


function rft_load_themes()
{

    global $context, $modSettings;

if (isset($_REQUEST['xml']))
return;
   
    loadTemplate('RecentForumTopics');

    $context['template_layers'][] = 'rft';
}



That should prevent your templates from been called when sending XML data.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Diego Andrés

I didn't know I could do that lol  :-[

I was doing something like this

$position = array_search('body', $context['template_layers']);
if ($position === false)
$position = array_search('main', $context['template_layers']);

if ($position !== false)
{
$before = array_slice($context['template_layers'], 0, $position + 1);
$after = array_slice($context['template_layers'], $position + 1);
$context['template_layers'] = array_merge($before, array('shop'), $after);
}


So thanks, I found this topic very useful

SMF Tricks - Free & Premium Responsive Themes for SMF.

Advertisement: