I'm trying to create a templated file with jinja2 and ansible
currently i have a dict with multiple entries e.g:
internal_sites:
- {name: "site1" ,url: "site1.example.com" }
- {name: "site2" ,url: "site2.example.com" }
- {name: "site3" ,url: "site3.example.com" }
- {name: "site4" ,url: "site4.example.com" }
I have a a directory that has multiple files eached also named after the value in 'name'
├── templates
│ ├── base.cfg.j2
│ └── services
│ ├── internal
│ │ ├── site1.txt
│ │ ├── site2.txt
│ │ ├── site3.txt
│ │ ├── site4.txt
Within base.cfg.j2 im trying to loop over each item in internal_sites which generates the appropriate config i require and at the same time im trying to include the content of the text files.
the instructions i have are as follows:
{% for site in internal_sites %}
acl {{ site.name }} hdr(host) -i {{ site.url }}
use_backend {{ site.name }} if {{ site.name }}
backend {{ site.name}}
{% include "templates/services/internal/"{{lookup('vars', site.name)}} %}
{% endfor %}
however whenever i run my ansible i get the following error;
FAILED! => {"changed": false, "msg": "AnsibleError: template error while templating string: expected token 'end of statement block', got '{'. String: \n{% for site in internal_sites %}\n acl {{ site.name }} hdr(host) -i {{ site.url }}\n use_backend {{ site.name }} if {{ site.name }}\n\n backend {{ site.name}}\n {% include \"templates/services/internal/\"{{lookup('vars', site.name)}} %}\n\n{% endfor %}\n"}
i have also tried with the following
{% for site in internal_sites %}
{% set fileloc = 'templates/services/internal/' + site.name %}
acl {{ site.name }} hdr(host) -i {{ site.url }}
use_backend {{ site.name }} if {{ site.name }}
backend {{ site.name}}
{% include {{fileloc}} %}
{% endfor %}
I'm aware this is likely wrong but could anyone shed some guidance on the most appropriate way to do this?
expected output
acl site1 hdr(host) -i site1.example.com
use_backend site1 if site1
backend site1
contents of site1.txt
are included
here
I'm having n issue with loading html files with go gin framework
when i loaded the entire templates folder from the main function its not reading the subdirectories and only read files .
package app
import (
"github.com/gin-gonic/gin"
)
var (
router = gin.Default()
)
func StartApp() {
router.LoadHTMLGlob("templates/*/*.html")
routersMap()
router.Run(":8080")
}
based on the project structure it supposed to show the Loaded HTML Templates as
[GIN-debug] Loaded HTML Templates (2):
- layouts/default.html
- layouts/index.html
- pages/index.html
but actually the output showing this result
[GIN-debug] Loaded HTML Templates (3):
- default.html
- index.html
-
it doesn't even showing the second index.html file
Project Structure
I am also working on learning go and using gin.
I came across this issue also and ran into a few minor issues that i resolved.
I will leave this here in case it may someone else.
Folder layout:
.
├── controllers
│ ├── controller.go
│ └── gui.go
├── html
│ └── templates
│ ├── homepage
│ │ └── index.html
│ ├── layouts
│ │ ├── footer.html
│ │ ├── header.html
│ │ └── menu.html
│ └── views
│ └── library.html
├── models
│ ├── bookstruct.go
│ └── dbconnection.go
├── server.go
└── test
└── server_test.go
The part that is probably needed are these files:
server.go
gui.go
library.html
gui.go
package controllers
import (
"net/http"
"github.com/gin-gonic/gin"
)
...
// BooksView display book library
func BooksView(c *gin.Context) {
c.HTML(
http.StatusOK,
"views/library.html",
gin.H{"title": "Books"},
)
}
library.html
{{ define "views/library.html" }}
<!--Embed the header.html template at this location-->
{{ template "layouts/header.html" .}}
<h1>Hello Books!</h1>
<div>Est nisi debitis recusandae necessitatibus voluptate ut. Laudantium eligendi nostrum quisquam voluptates harum
exercitationem nam harum. Voluptatem sit assumenda sit alias dolores. Modi autem et temporibus impedit qui numquam.
Esse ut recusandae quos deserunt nihil repellendus. Sint et voluptatem quia quia dolor aut.</div>
<div>Est nisi debitis recusandae necessitatibus voluptate ut. Laudantium eligendi nostrum quisquam voluptates harum
exercitationem nam harum. Voluptatem sit assumenda sit alias dolores. Modi autem et temporibus impedit qui numquam.
Esse ut recusandae quos deserunt nihil repellendus. Sint et voluptatem quia quia dolor aut.</div>
<!--Embed the footer.html template at this location-->
{{ template "layouts/footer.html" .}}
{{ end }}
server.go
import (
c "go_first_api/sub_packages/gormrestapi/controllers"
m "go_first_api/sub_packages/gormrestapi/models"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
)
// RunServer will run and create a server using gin
func RunServer() {
...
r := gin.Default()
r.LoadHTMLGlob("sub_packages/gormrestapi/html/templates/**/*")
r.GET("/library", c.BooksView)
...
r.Run(":8088")
}
NOTE: main.go is above this sub-dir in the folder path.
See gin#html-rendering,
Using templates with same name in different directories templates/**/*.
I am following this link to figure out how to create an archives page. I am using the hugo-xmin theme with slight modifications.
As far as I understand, range goes through the pages and should print them out. But, I am getting an additional 0001 also. I don't understand why. I'm still a beginner to Hugo and Go.
My output (circled portion in red not what I want)
My archives.html
{{ partial "header.html" . }}
<div class="article-meta">
<h1><span class="title">{{ .Title | markdownify }}</span></h1>
{{ with .Params.author }}<h2 class="author">{{ . }}</h2>{{ end }}
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
</div>
<main class="content" role="main">
<div class="inner">
{{ range (.Site.RegularPages.GroupByDate "2006") }}
<h3>{{ .Key }}</h3>
<ul>
{{ range (where .Pages "Type" "post") }}
<li>
<span class="date">{{ .Date.Format "2006/01/02" }}</span>
{{ .Title }}
</li>
{{ end }}
</ul>
{{ end }}
</div>
</main>
{{ partial "footer.html" . }}
My archives.md
---
title: "Archives"
layout: "archives"
draft: false
---
This is archives
My directory structure
.
├── archetypes
│ └── default.md
├── config.toml
├── content
│ ├── about.md
│ ├── archives.md
│ ├── _index.md
│ ├── post
│ │ ├── first_post.md
│ │ ├── sample_code.md
│ │ └── test_math.md
│ └── reading.md
├── data
├── layouts
├── static
└── themes
└── mytheme
├── archetypes
│ └── default.md
├── layouts
│ ├── 404.html
│ ├── archives.html
│ ├── _default
│ │ ├── archives.html
│ │ ├── list.html
│ │ ├── single.html
│ │ └── terms.html
│ ├── index.html
│ └── partials
│ ├── foot_custom.html
│ ├── footer.html
│ ├── head_custom.html
│ └── header.html
├── LICENSE.md
├── static
│ ├── css
│ │ ├── fonts.css
│ │ └── style.css
│ └── js
└── theme.toml
15 directories, 25 files
I changed my archives.html to the following, with some help from hugo-lithium. It works for my use case now. But I still don't understand why the 0001 came up in the first place. So I will not be marking my answer as correct for now.
{{ partial "header.html" . }}
<div class="article-meta">
<h1><span class="title">{{ .Title | markdownify }}</span></h1>
{{ with .Params.author }}<h2 class="author">{{ . }}</h2>{{ end }}
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
</div>
{{ range (where .Site.RegularPages "Section" "!=" "").GroupByDate "2006" }}
<h2>{{ .Key }}</h2>
<ul>
{{ range .Pages }}
<li>
<span class="date">{{ .Date.Format "2006/02/02" }}</span>
{{ .Title }}
</li>
{{ end }}
</ul>
{{ end }}
{{ partial "footer.html" . }}
I am trying to create a new model for Odoo 11 that is installed on Centos 7. When it comes to using that model, Odoo does not detect it. Here is the structure of the model:
student_contact
models
__init__.py
student.py
views
student_view.py
security
ir.model.acces.csv
__init__.py
__manifest__.py
init.py:
# -*- coding: utf-8-*-
from . import models
manifest.py:
# -*- coding:utf-8 -*-
{
'name': 'fiche',
'version':'12.0.1.0.0',
'summary': 'Record Student Information',
'category': 'Tools',
'author': 'BOUICHE Kheireddine',
'maintainer': 'INSIM Bejaia',
'company': 'INSIM Bejaia',
'website': 'https://www.insim.dz',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/student_view.xml'
],
'images':[],
'license': 'AGPL-3',
'installable': True,
'application': False,
'auto_install': False,
}
views/student_view.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record id="student_menu_action" model="ir.actions.act_window">
<field name ="name">Students</field>
<field name ="res_model">student.student</field>
<field name ="view_type">form</field>
<field name ="view_mode">tree, form </field>
<field name ="help" type="html">
<p class="oe_view_nocontent_create"> Create The Firste Student
</p>
</field>
</record>
<menuitem id="school_menu"
name="School" />
<menuitem id="school_student_menu"
parent="school_menu"
name="Student"
action="student_menu_action" />
</data>
</odoo>
models/init.py:
# -*- coding: utf-8 -*-
from . import student
models/student.py:
# -*- coding: utf-8 -*-
from odoo import models, fields
class StudentStudent(models.Model):
_name = 'student.student'
name = fields.Char(string='Name', required=True)
age = fields.Integer(string='Age')
photo = fields.Binary(string='Image')
gender = fields.Selection([('male','Male'),('female','Female'),('others','Others')],string='Gender')
student_dob = fields.Date(string="Date of Birth")
student_blood_group = fields.Selection(
[ ('A+','A+ve'), ('B+','B+ve'),('O+','O+ve'),('AB+','AB+ve'),
('A-','A-ve'),('B-','B-ve'),('O-','O-ve'),('AB-','AB-ve')], string='Blood Group'
)
nationality = fields.Many2one('res.country', string='Nationality')
security/ir.model.access.csv :
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_student_student,access.student.student,model_student_student,base.group_user,1,1,1,0
The structure is good, Do you get any error?
And also remember:
Restart the server
update the app list
Then install your module
The final view should like this:
The code in view.xml like this:
<VBox height="90px">
<Label text="{i18n>FISCALYEAR_LABEL}" mandatory="mandatory"/>
<Select id="FiscalYear"
items="{
path: '/FiscalYearSet',
sorter: { path: 'FiscalYearID' }
}">
<core:Item key="{FiscalYearID}" text="{FiscalYearNum}" />
</Select>
<ComboBox
items="{
path: '/FiscalYearSet',
sorter: { path: 'FiscalYearID' }
}">
<core:Item key="{FiscalYearID}" text="{FiscalYearNum}" />
</ComboBox>
</VBox>
I set a property 'mandatory="mandatory"', but it does not work.
<Label text="{i18n>FISCALYEAR_LABEL}" required='true'/>
required is one of the properties of sap.m.InputBase with default boolean value set to false