How can I refresh the page

How can I refresh the page

by Sascha Schrader -
Number of replies: 8

I've got my plugin to the point where I can save entries. Now I want to return to the previous page after saving and have the page refresh automatically.

What functions are there to refresh the page? Unfortunately, if I've seen it correctly, the documentation isn't very informative.

రేటింగుల సగటు: -
In reply to Sascha Schrader

Re: How can I refresh the page

by Mark Johnson -
Core developers బొమ్మ Particularly helpful Moodlers బొమ్మ Peer reviewers బొమ్మ Plugin developers బొమ్మ

If you have a form where you submit an entry, you should have the form processing code save the change, then redirect you back to the previous page using redirect(). The page you are redirecting to should then load with the updated entries, you shouldn't need to refresh the page further.

The exception for this would be if you are using a modal form, and you want the underlying page to load the updated data when you save. If this is what you're doing, I can point you to some examples.

In reply to Mark Johnson

Re: How can I refresh the page

by Sascha Schrader -

Sorry for not getting back to you until now. I've been sick for a few weeks. Thank you for your info!

I would like to follow your example. So far I've tried the following:

My Button:

<ion-button size="small" class="check" core-site-plugins-call-ws name="local_schultimer_comment_check" goBackOnSuccess="true" (onSuccess)="messagesUpdated()" [params]="{cid: <% id %>, susid: <% susid %>}">

My JavaScript:

const translate = key => this.TranslateService.instant(`plugin.local_schultimer.${key}`);
const observer = this.CoreEventsProvider.on('local_schultimer:messages-updated', () => this.refreshContent());

this.ngOnDestroy = () => observer.off();

and:

this.messagesUpdated = () => this.CoreEventsProvider.trigger('local_schultimer:messages-updated');

I load the files into the file mobile.php in the folders classes->output->mobile.php

return [
            'templates' => [
                [
                    'id' => 'main',
                    'html' => $html,
                ],
            ],
            'javascript' => file_get_contents( __DIR__ . '/../../js/mobile/view_schultimer_list.js' ),
        ];

Can I load a second JavaScript file? This line:

this.messagesUpdated = () => this.CoreEventsProvider.trigger('local_schultimer:messages-updated');

is in another file and is not loaded.

Thank you very much for your help!

In reply to Mark Johnson

Re: How can I refresh the page

by Sascha Schrader -

Does anyone have a tip for me on how to do the refresh?

In reply to Sascha Schrader

Re: How can I refresh the page

by Michael Milette -
Core developers బొమ్మ Documentation writers బొమ్మ Particularly helpful Moodlers బొమ్మ Plugin developers బొమ్మ Testers బొమ్మ Translators బొమ్మ

Hi Sascha,

Here are a few suggestions on how to refresh a page:

  1. Press F5, Shift F5, CTRL-F5, or CTRL-R; (not in Moodle App)
  2. Click a link to the same page you are on, adding a datestamp parameter to the URL so that the browser doesn't reload from cache; or
  3. Use JavaScript. Use the same technique as #2 above to avoid cache.

Hope you find this information helpful.

Best regards,

Michael Milette

In reply to Sascha Schrader

Re: How can I refresh the page

by Angélique Dubois-Chabert -
Hi again Sascha !
Just wanted to inform you that, as I need to reload for all navigation to that page, I decided I can use

const url = 'https://example.com/data' + `?cache_bust=${Date.now()}`;