i'm stuck with this problem. I had 2 different modules that make different thinks and all two need the tag for Safari iOS WebApp for adding web page as native APP:
<link rel="apple-touch-icon" href="ic_launcher-web.png"/>
<meta name="apple-mobile-web-app-title" content="Title"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
But the problem is that all two gets loaded because i inherit web.assets_frontend and add them into it that will add them into <head></head>
.
It's possible to load dynamically the assets or css and js resources? Something like.. load this templates when the relative template of web pages gets rendered by controller?
Only add this to when template 1 is rendered
<template id="for_app_1">
<link rel="apple-touch-icon" href="ic_launcher-web1.png"/>
<meta name="apple-mobile-web-app-title" content="Title 1"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
</template>
Only add this to when template 2 is rendered
<template id="for_app_2">
<link rel="apple-touch-icon" href="ic_launcher-web2.png"/>
<meta name="apple-mobile-web-app-title" content="Title 2"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
</template>
I found the solution into addons/web/views/webclient_templates.xml
As you can see they define a <t t-set='head'>
and inside it a <t t-call-assets>
that call a template called assets_common
, defined above.
So with this t-set='head'
and t-call-assest
they put the declared assets_common inside head only when template web.login_layout
is rendered!
<template id="web.login_layout" name="Login Layout">
<t t-call="web.layout">
<t t-set="html_data" t-value="{'style': 'height: 100%;'}"/>
<t t-set="head">
<t t-call-assets="web.assets_common" t-js="false"/>
<t t-call-assets="web.assets_frontend" t-js="false"/>
<t t-call-assets="web.assets_common" t-css="false"/>
<t t-call-assets="web.assets_frontend" t-css="false"/>
</t>
<t t-set="body_classname" t-value="'container'"/>
<div class="row">
<div class="col-md-6 col-md-offset-3 o_database_list">
<div class="text-center">
<img t-attf-src="/web/binary/company_logo{{ '?dbname='+db if db else '' }}"/>
</div>
<t t-raw="0"/>
<div class="text-center" t-if="not disable_footer">
<t t-if="not disable_database_manager">
<a class="" href="/web/database/manager">Manage Databases</a> |
</t>
<a href="https://www.odoo.com" target="_blank">Powered by <span>Odoo</span></a>
</div>
</div>
</div>
</t>
</template>
Here the web.assets_common where they declare all the css and javascript that is usefull for the template login_layout.
<template id="web.assets_common" name="Common Assets (used in backend interface and website)">
<t t-call="web.less_helpers"/>
<link rel="stylesheet" type="text/css" href="/web/static/lib/jquery.ui/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="/web/static/lib/fontawesome/css/font-awesome.css"/>
<link rel="stylesheet" type="text/less" href="/web/static/lib/bootstrap-datetimepicker/src/less/_bootstrap-datetimepicker.less"/>
<link rel="stylesheet" type="text/css" href="/web/static/lib/select2/select2.css"/>
<link rel="stylesheet" type="text/css" href="/web/static/lib/select2-bootstrap-css/select2-bootstrap.css"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/fonts.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/navbar.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/mimetypes.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/modal.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/animation.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/rainbow.less"/>
<link rel="stylesheet" type="text/less" href="/web/static/src/less/datepicker.less"/>
<!-- And ore stuffs -->
</template>
So if you need some certain assets loaded only in a precise template, you can just set inside defined in the top elements inside template and inside it call the template with assets that you need.
Reference : https://www.odoo.com/documentation/11.0/reference/javascript_reference.html#assets-management