MDL-72845 core: make campaign template more generic

This commit is contained in:
Simey Lameze 2021-12-22 19:32:18 +08:00
parent 5c05b019ae
commit c3cb372e62
2 changed files with 19 additions and 9 deletions

View File

@ -895,7 +895,14 @@ class core_admin_renderer extends plugin_renderer_base {
return '';
}
return $this->render_from_template('core/campaign_content', ['lang' => current_language()]);
$lang = current_language();
$url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
$params = [
'url' => $url,
'iframeid' => 'campaign-content'
];
return $this->render_from_template('core/external_content_banner', $params);
}
/**

View File

@ -15,11 +15,11 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/campaign_content
@template core/external_content_banner
Moodle campaign content template.
Moodle external content banner template.
The purpose of this template is to render an iframe that contains campaign content.
The purpose of this template is to render an iframe that contains external content banner.
Classes required for JS:
* none
@ -31,17 +31,20 @@
* lang User's language.
Example context (json):
{ "lang": "en"}
{
"iframeid": "external-content",
"url": "http://example.com/link",
}
}}
<div class="alert alert-secondary alert-block fade in">
<iframe id="campaign-content" class="w-100 border-0"></iframe>
<iframe id="{{iframeid}}" class="w-100 border-0"></iframe>
</div>
{{#js}}
(function() {
var iframe = document.getElementById('campaign-content');
iframe.src = 'https://campaign.moodle.org/current/lms/{{lang}}/';
var iframe = document.getElementById('{{iframeid}}');
iframe.src = '{{url}}';
window.addEventListener('message', function (event) {
if (event.origin === 'https://campaign.moodle.org') {
if (event.source === iframe.contentWindow) {
iframe.style.height = event.data + 'px';
}
});