I just need a basic page to show some static information in a <p> tag. How can I create a form that has no model?
For this you can create a QWeb Report wich are standard web pages.
openacademy/views/report.xml
<template id='template_id'>
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<h2>Report title</h2>
<p> report text </p>
</div>
</t>
</t>
</t>
</template>
Place the report in the manifest file
openacademy/manifest.py
# always loaded
'data': [
'views/openacademy.xml',
'views/report.xml',
],
Documentation on QWeb Report
The best way to solve this is with simple Odoo MVC. Just create a controller that will render a view; define the view to be rendered and register the view. I found a tutorial here: https://www.odoo.yenthevg.com/creating-webpages-controllers-odoo10/
Note that (as of the time of this posting) the tutorial has an error in the view's XML -- line 16 and 17 need to be swapped so that the XML is nested properly.
Related
I need to change size of logo on invoice header only. At first attempt I tried this for selected layout:
<template id="external_layout_bold_ksp" inherit_id="web.external_layout_bold">
<xpath expr="//div[#t-attf-class='header o_company_#{company.id}_layout']/div/div/div/img"
position="replace">
<img t-if="company.logo" style="max-width: 350px;max-height: 190px;"
t-att-src="image_data_uri(company.logo)" alt="Logo"/><br/>
</xpath>
</template>
it worked but it is changing all logos of all pdf reports for bold layout, unable to find logo path in report template report_invoice_document. I need to resize only invoice report's logo
I have applied something like that in Odoo 11 and it will work on other versions.
To resize the logo in invoice report only, you need to pass value through context from invoice report and then check it in the external layout bold template.
I have added change_logo_size Boolean context value from invoice report and set it to true as below:
<template id="report_invoice_document_logo" inherit_id="account.report_invoice_document">
<xpath expr="//t[#t-call='web.external_layout']" position="before">
<t t-set="o" t-value="o.with_context(change_logo_size= True)"/>
</xpath>
</template>
hen in the inheritance of external layout bold, I have checked the value from the context and if it's true then apply the replace for image, otherwise leave it as its:
<template id="external_layout_bold_ksp" inherit_id="web.external_layout_bold">
<xpath expr="//div[#t-attf-class='header o_company_#{company.id}_layout']/div/div/div/img" position="replace">
<t t-if=" o and o.env and 'change_logo_size' in o.env.context and o.env.context.get('change_logo_size',False)">
<img t-if="company.logo" style="max-width: 350px;max-height: 190px;"
t-att-src="image_data_uri(company.logo)" alt="Logo"/>
</t>
<t t-else="">
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" alt="Logo"/>
</t>
</xpath>
</template>
I am trying to add existing division of Odoo product template in a new division. for that, I can do the "replace" of the whole division. and add my custom division.
for example, here is default Odoo template section with the div.
<section t-attf-class="container mt8 oe_website_sale" id="product_detail">
<div class="row" id="odoo_default_row">
</div>
</section>
and I wanted to add odoo_default_row div in my custom div element. like
<section t-attf-class="container mt8 oe_website_sale" id="product_detail">
<div id="my_custom_div">
<div class="row" id="odoo_default_row">
</div>
</div>
</section>
what is the best way to add existing division in the custom division despite using xpath replace?
We can replace whole div element using "replace" attribute. With these, we can freely design custom div element.
Try with following code:
<div id="odoo_default_row" position="replace">
<!-- Design your div element as per your requirement-->
</div>
NOTE:
As per my understanding with your situation is that "inside" attribute will not work.
I'm trying to yield a section inside another section. But this does not work as expected, I see blank output.
#section('3show')
This is a text string
#stop
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
<!--#content-->
#stop
Any ideas to yield section inside another section ?
Ok, this is what I tried and I can confirm that this works, at least for Laravel 5+ (I have L5.2). This is how I suggest you to use your blade templates.
Lets start saying that to yield a section into another section you have to define your included section before container section definition. So, with that clear, I solved this situation like this:
I got a main blade (main.blade.php) template which has something like:
<section class="content">
<!-- Your Page Content Here -->
#yield('main-content')
</section><!-- /.content -->
I got a second blade (common.blade.php) template which has that common stuff you may want to show across many pages and where main-content section is defined. This one looks like:
#section('main-content')
<div class="container">
#yield('extra-content')
</div>
#endsection
Finally I got a 3rd template (test.blade.php) which extend the main template and include the common stuff I want to show, but be careful because the order matters. This one looks like:
#extends('main')
#section('extra-content')
<div>
<span> This is a test! </span>
</div>
#endsection
#include('common')
In your controller or your route (wherever you return your view), you should return the 3rd template.
In my projects i create some partials in order to have cleaner code and i give them as an example a name : 3show.blade.php. In order to use them in a section i just include them.
I think this will do what you want.
#section('content')
#include('3show.blade.php')
#endsection
I had the same issue.
You can't use the #extends option in this case, you need to use #include .
So lets say you have:
the root layout (layouts/app.blade.php)
an extra layout (layouts/extra.blade.php)
the actual view that you are calling (someview.blade.php)
The solution is to use add/inherit the root layout (1) to the top line of your view (3):
#extends('layouts.app')
Next, add/inherit the extra layout (2) to the second line of your view, BUT use #include not #extends:
#include('layouts.extra')
...and remember to wrap the content of your extra layout in an #section name, for example #section('extra')
Finally you can call your extra layout content from your view:
<p>Look below, you will see my extra content...</p>
#yield('extra')
So in summary, your someview.blade.php view would look like:
#extends('layouts.app')
#include('layouts.extra')
#section('content')
<p>Look below, you will see my extra content...</p>
#yield('extra')
#endsection
solution 1:
you can use #show instead of #stop at the end of section
then laravel will render your #yield parts ...
like this :
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
#show # not #stop
#section('3show')
This is a text string
#stop
this way render you view and show result
so if you cll your section for twice then result will be shoed twice
solution 2:
insert call section before yiel it
like this :
**first call section :**
#section('3show')
This is a text string
#stop
**then define your section : 3show**
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
#stop **not #show**
assume you have two files:
-article_base.blade.php -> the default data in every article.
-article_index.blade.php -> the customized file.
article_base.blade.php
#extends('layout')
#section('page-content')
<div id="content">
<article>
....
#yield('3show')
....
</article>
</div>
<!--#content-->
#stop
article_index.blade.php
#extends('article_base')
#section('3show')
This is a text string
#endsection
I hope this works
You have to both #include and #yield the child template in your main template to be able to add the child template at a specific place inside the main template (not just before or after the main template - this is done by adding #parent in the child template - but in between):
main.blade.php
#include('child')
<div>
...
#yield('child')
</div>
child.blade.php
#section('child')
<div>
...
</div>
#endsection
I am trying out Playframework with Polymer as a GUI tool. As a JSF developer, I am not really used to developing these ajax codes.
For now, I have this situation in my main.scala.html:
<core-scaffold>
<core-header-panel navigation flex mode="seamed">
<core-toolbar>Painel Administrativo</core-toolbar>
<nav>
<core-menu selected="0">
<paper-item noink>
<a href="#routes.ProjetoController.listar()">
<core-icon icon="settings"></core-icon> Projetos
</a>
</paper-item>
<paper-item noink>
<a href="#routes.TipoProjetoController.listar()">
<core-icon icon="settings"></core-icon>Tipos de Projetos
</a>
</paper-item>
</core-menu>
</nav>
</core-header-panel>
<div tool></div>
<div fit>#content</div>
</core-scaffold>
Question is: Is there a way of calling the routes I have into the paper-item elements and partially render it into #content ?? If so, how could I achieve this one page style behavior, without the page resfresh?
PS.: these are not static content.
ProjetoController.listar() should render projeto_listar.scala.html and TipoProjetoController.listar() should render tipoProjeto_listar.scala.html. Those are 2 different dynamic pages which implments main:
#()
#main("Page Title") {
}
Take a look at Page.JS, you can make all the routes in the single page format.
I have a partial view which consists of a div with a benner that I change once a week.
This banner is embedded within 10 pages that have the same layout.
Give a page like Index.cshtml or AboutUs.cshtml, both being partial views and having the laypout _Layout.cshtml my question is:
Can I inser code in Index.cshtml or AboutUs.cshtml that renders Banner.cshtml?
something like:
inside Index.cshtml or AboutUs.cshtml I have #Html.Renderbanner("banner.cshtml");
Yes,
#{ Html.RenderPartial("_Banner"); }
In your shared view folder, add your partial view and call it _Banner.cshtml
Sure, you could always:
#Html.Partial("Banner")
from any view or partial view. This will render the Banner.cshtml partial at the place where you called this helper.
Use #Html.RenderPartial("YourViewName");
First, just to clarify: Are Index and AboutUs really partial views in your scenario? That may
change my advice, but normally I see three options:
Razor Helper, create Banner.cshtml in App_Code with the following code:
#helper Show(){
<img src="mybanner.png"/>
}
Then call in Index.cshtml:
#Banner.Show()
Html Helper Extension, a bit overkill here probably (see tutorial on web)
Partial View: Create "_MyBanner.cshtml" and use the following in Index.cshtml:
#Html.Partial("_MyBanner");
(Number 3 is the one that might be tricky if Index and AboutUs are also partial views, but 1 the one I would choose.)
Note: There is a difference between Html.Partial and Html.RenderPartial. The latter writes directly to the output stream and will require you to call it in parentheses. In MVC AFAIK it is best practice to use Html.Partial.
You can create a RenderSection in layout.cshtml
#if (IsSectionDefined("Sidebar"))
{
<div id="page">
<!-- end #content -->
<div id="content">
#RenderBody()
</div>
<div id="sidebar">
#RenderSection("Sidebar", required: false)
</div>
<div style="clear: both;">
</div>
</div>
<!-- end #page -->
<!-- end #sidebar -->
}
else
{
<div id="page">
<!-- end #content -->
<div id="content2">
#RenderBody()
</div>
<div style="clear: both;">
</div>
</div>
<!-- end #page -->
<!-- end #sidebar -->
}
if you need see the secction in about.cshtml
use
#section Sidebar{
#Html.Partial("_yourbanner")
}
if you dont need the banner do not include it