Jump to content

Adding alerts to the smarty variable


CassidyDNS

Recommended Posts

Does anyone know if there is a way I can add alerts into the smarty variable please? In the clientareadomaindetails.tpl file, we have the below:

{if $alerts}
    {foreach $alerts as $alert}
        {include file="$template/includes/alert.tpl" type=$alert.type msg="<strong>{$alert.title}</strong><br>{$alert.description}" textcenter=true}
    {/foreach}
{/if}

I would like to add to these alerts to display my own custom messages. Using the below I have managed to create my own custom alerts within my registrar module

function modulename_ClientArea($params) {
    global $smarty;
    
    $alerts = array();
    
    $alerts[] = array(
        'title' => 'Title',
        'description' => 'description',
        'type' => 'info'
    );
    
    $smarty->assign('customalerts', $alerts);
    
    return '';
}

But this would involve maintaining the tpl file mentioned above, which I'd like to avoid. I have tried the below as well, but anything I add doesn't exist by the time it gets the tpl file gets loaded, even when there are alerts already in the array when I add to them.

function modulename_ClientArea($params) {
    global $smarty;
    
    $alerts = $smarty->getTemplateVars('alerts');

    $alerts[] = array(
        'title' => 'Title',
        'description' => 'description',
        'type' => 'info'
    );

    $smarty->assign('alerts', $alerts);
    
    return '';
}

FYI the reason I am not simply returning the alerts as html instead is because they would be put at the bottom of the domain overview page.

Link to comment
Share on other sites

1 hour ago, CassidyDNS said:

I have tried the below as well, but anything I add doesn't exist by the time it gets the tpl file gets loaded, even when there are alerts already in the array when I add to them.

if that's v8, i'm not sure that gTV would work as it might get blocked by the Smarty Security Policy.

I also wouldn't bother using smarty assign, i'd just be returning the arrays in the return.

1 hour ago, CassidyDNS said:

FYI the reason I am not simply returning the alerts as html instead is because they would be put at the bottom of the domain overview page.

only because that's the current position where they're output is specified in the clientareadomaindetails template (line ~ 120) - there's nothing to stop you moving that block to the top by the alerts code you specify.. same would apply to the hook output if you used ClientAreaDomainDetailsOutput (though if you're in a registrar module, you shouldn't need to use that I wouldn't have thought).

annoyingly I couldn't find a domain with an existing alert, but if you can get the existing alerts array (won't exist unless there are existing alerts), you should be able to append it - assuming the array exists before the module runs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated