Re: [go-nuts] template

2020-07-23 Thread Tharaneedharan Vilwanathan
Hi Lutz,

Sorry I was not clear earlier. Yes, this is regarding Go HTML template.

We use beego and HTML templates under that.

We generally use nested templates in which we have nested if conditions as
needed and for loop (range). We also do some minor computation, etc.

I feel over time, the template file has gone out of shape and
became difficult to understand and maintain. Hence my questions.

Hope this helps. Please let me know if you have any questions.

Regards
dharani


On Wed, Jul 22, 2020 at 11:54 AM Lutz Horn  wrote:

> > I am running a website for which we use templates.
>
> Do you use https://golang.org/pkg/html/template/? If yes, how do you use
> them? If no, this question is off-topic for this mailing list.
>
> Lutz
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/AM7P191MB1060A58CEA463342E216714B9E790%40AM7P191MB1060.EURP191.PROD.OUTLOOK.COM
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN-HoCnypth1P2UKcuR_aObYryDmmVG0-M3%2BBtKzScNMtZ7w2g%40mail.gmail.com.


Re: [go-nuts] template

2020-07-22 Thread Lutz Horn

I am running a website for which we use templates.


Do you use https://golang.org/pkg/html/template/? If yes, how do you use 
them? If no, this question is off-topic for this mailing list.


Lutz

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/AM7P191MB1060A58CEA463342E216714B9E790%40AM7P191MB1060.EURP191.PROD.OUTLOOK.COM.


[go-nuts] template

2020-07-21 Thread Tharaneedharan Vilwanathan
Hi All,

I am running a website for which we use templates.

While I see the benefit of templates, I also notice that it has gotten ugly
over time.

So, here are my questions:

- Are templates popular? Or do you avoid using it?
- Any do's and don'ts? Any best practices?
- Any suggestions on formatting of templates?

Regards
dharani

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN-HoCnf81jHTTOuT7D4xAkwb8191x13vhiRZJ1puGypwAHh1w%40mail.gmail.com.


[go-nuts] Template function arguments from JS

2018-10-17 Thread Volodymyr Salo
Hi! I have some template which gets populated based on some function, but 
the latter gets an argument from javascript code, defined in the same 
template. Of course, it doesn't work, as js code doesn't get executed 
within the template context. Code is as follows:


function getMonth() {
return $("#month").find(":selected").text();
}




Month

{{range .Months}}
{{.Name}}
{{end}}






Week
Max users

{{range $week, $num := .Report getMonth()}} //This doesn't work

{{$week}}
{{$num}}

{{end}}




Could anyone please suggest, how to resolve this thing?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Fwd: [go-nuts] Template func ParseFiles, parsing multiple files

2017-07-13 Thread Tong Sun
Thanks a lot Nathan.

-- Forwarded message --
From: Nathan Kerr
Date: Thu, Jul 13, 2017 at 3:48 AM
Subject: Re: [go-nuts] Template func ParseFiles, parsing multiple files
To: Tong Sun


MyTempl will have different templates after the second call. The template
called “tf1” from the first call will be replaced with the template found
in “tf1” from the second call.

MyTempl.Execute() will use the name of the first template that was parsed,
in this case “tf1"


On Jul 6, 2017, at 21:59, Tong Sun <suntong...@gmail.com> wrote:

Thanks Nathan.

I'm still confused.

>* ParseFiles adds a new template to the collection with the filename as
its name*

So if my MyTempl was named "tf1", calling MyTempl.ParseFiles() with more
than one files will have new templates created according to each of the
passed filename? Or the template name never changes regardless how many
files are passed in `ParseFiles()`?

I.e., for

 MyTempl := tt.New("tf1")

MyTempl.ParseFiles("tf1")
MyTempl.ParseFiles("tf1","tf2")

Would MyTempl have different template names after above each statement? If
so, then which one does the `MyTempl.Execute()` uses?


On Thursday, July 6, 2017 at 1:49:54 PM UTC-4, Nathan Kerr wrote:
>
> A text.Template contains one or more named templates. ParseFiles adds a
> new template to the collection with the filename as its name. Template
> names are used to tell Template.ExecuteTemplate
> <https://godoc.org/text/template#Template.ExecuteTemplate> which of the
> included templates to execute.
>
> On Thursday, July 6, 2017 at 6:37:01 AM UTC+2, Tong Sun wrote:
>>
>> What would it happen if I pass two or more files to:
>>
>> func (*Template) ParseFiles
>> <https://golang.org/src/text/template/helper.go#L52>
>> ❖ <https://golang.org/src/text/template/helper.go#L52>
>>
>> func (t *Template <http://godoc.org/text/template#Template>) 
>> ParseFiles(filenames ...string <http://godoc.org/builtin#string>) (*Template 
>> <http://godoc.org/text/template#Template>, error 
>> <http://godoc.org/builtin#error>)
>>
>> ParseFiles parses the named files and associates the resulting templates
>> with t. If an error occurs, parsing stops and the returned template is nil;
>> otherwise it is t. There must be at least one file. Since the templates
>> created by ParseFiles are named by the base names of the argument files, t
>> should usually have the name of one of the (base) names of the files. If it
>> does not, depending on t's contents before calling ParseFiles, t.Execute
>> may fail. In that case use t.ExecuteTemplate to execute a valid template.
>>
>> When parsing multiple files with the same name in different directories,
>> the last one mentioned will be the one that results.
>>
>> E.g.,
>>
>> What would the differences be that affects the output, for
>>
>> MyTempl.ParseFiles(tf1)
>>
>> vs.
>>
>> MyTempl.ParseFiles(tf1,tf2)?
>>
>> Will the content of tf2 be appended to tf1?
>>
>> Thx
>>
>>
-- 
You received this message because you are subscribed to a topic in the
Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/golang-nuts/LGJJdrHsD78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Template func ParseFiles, parsing multiple files

2017-07-05 Thread Tong Sun
What would it happen if I pass two or more files to:

func (*Template) ParseFiles 


func (t *Template ) 
ParseFiles(filenames ...string ) (*Template 
, error 
)

ParseFiles parses the named files and associates the resulting templates 
with t. If an error occurs, parsing stops and the returned template is nil; 
otherwise it is t. There must be at least one file. Since the templates 
created by ParseFiles are named by the base names of the argument files, t 
should usually have the name of one of the (base) names of the files. If it 
does not, depending on t's contents before calling ParseFiles, t.Execute 
may fail. In that case use t.ExecuteTemplate to execute a valid template.

When parsing multiple files with the same name in different directories, 
the last one mentioned will be the one that results.

E.g., 

What would the differences be that affects the output, for 

MyTempl.ParseFiles(tf1)

vs. 

MyTempl.ParseFiles(tf1,tf2)? 

Will the content of tf2 be appended to tf1? 

Thx

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] template Funcs with ParseFile and Execute

2017-03-26 Thread Lee McLoughlin
Try changing the call to New to name the template the same as the first 
parameter to ParseFiles

t, _ := template.New(templates.BASE).Funcs(funcMap).ParseFiles(templates.BASE, 
templates.NOTIFICATIONS, templates.TICKER, templateName)

There is something odd about how ParseFiles works if the name in New doesn't 
match.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] template Funcs with ParseFile and Execute

2017-03-25 Thread Rob Pike
Please check the error on the line that calls template.New. I believe it's
reporting failure.

-rob


On Sat, Mar 25, 2017 at 9:56 AM, priyank pulumati <
pulumati.priy...@gmail.com> wrote:

> Sry for little info, template.Base is a constant ("templates/base.html", a
> path) and the same for templateName passed from my controller.
> But what do i pass in template.New() ?
>
> On Saturday, March 25, 2017 at 10:17:23 PM UTC+5:30, Yves Junqueira wrote:
>>
>> Your ParseFiles call has a "templateName" argument in it. The ParseFiles
>> function only takes file paths, not template names.
>>
>> And templates.New takes a template name, not a file path.
>>
>> Hope this helps.
>>
>> On Sat, Mar 25, 2017 at 9:14 AM, priyank pulumati 
>> wrote:
>>
>>> hello,
>>> im building a go web app and facing an issue with Executing templates
>>> with custom functions
>>>
>>> func CustomTemplateExecute(res http.ResponseWriter, req *http.Request,
>>> templateName string, data map[string]interface{}) {
>>> // Append common templates and data structs and execute template
>>> var funcMap = template.FuncMap{
>>> "humanSize": humanSize,
>>> }
>>> t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE,
>>> templates.NOTIFICATIONS, templates.TICKER, templateName)
>>> if len(data) == 0 {
>>> data = make(map[string]interface{})
>>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>>> } else {
>>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>>> }
>>> t.Execute(res, data)
>>> }
>>>
>>> func humanSize() string {
>>> return "Hello"
>>> }
>>>
>>> I get template is empty error, i have tried giving a name to
>>> template.new and its the same error.
>>> Any help is appreciated, thank you !
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] template Funcs with ParseFile and Execute

2017-03-25 Thread priyank pulumati
Sry for little info, template.Base is a constant ("templates/base.html", a 
path) and the same for templateName passed from my controller.
But what do i pass in template.New() ?

On Saturday, March 25, 2017 at 10:17:23 PM UTC+5:30, Yves Junqueira wrote:
>
> Your ParseFiles call has a "templateName" argument in it. The ParseFiles 
> function only takes file paths, not template names.
>
> And templates.New takes a template name, not a file path.
>
> Hope this helps.
>
> On Sat, Mar 25, 2017 at 9:14 AM, priyank pulumati  > wrote:
>
>> hello,
>> im building a go web app and facing an issue with Executing templates 
>> with custom functions
>>
>> func CustomTemplateExecute(res http.ResponseWriter, req *http.Request, 
>> templateName string, data map[string]interface{}) {
>> // Append common templates and data structs and execute template
>> var funcMap = template.FuncMap{
>> "humanSize": humanSize,
>> }
>> t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE, 
>> templates.NOTIFICATIONS, templates.TICKER, templateName)
>> if len(data) == 0 {
>> data = make(map[string]interface{})
>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>> } else {
>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>> }
>> t.Execute(res, data)
>> }
>>
>> func humanSize() string {
>> return "Hello"
>> }
>>
>> I get template is empty error, i have tried giving a name to template.new 
>> and its the same error.
>> Any help is appreciated, thank you !
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] template Funcs with ParseFile and Execute

2017-03-25 Thread priyank pulumati
Sry for little information, templateName is passed from my controllers with 
a constant (like "templates/home.html"), so there is no problem with that.
In template.new(), what do i pass ?

On Saturday, March 25, 2017 at 10:17:23 PM UTC+5:30, Yves Junqueira wrote:
>
> Your ParseFiles call has a "templateName" argument in it. The ParseFiles 
> function only takes file paths, not template names.
>
> And templates.New takes a template name, not a file path.
>
> Hope this helps.
>
> On Sat, Mar 25, 2017 at 9:14 AM, priyank pulumati  > wrote:
>
>> hello,
>> im building a go web app and facing an issue with Executing templates 
>> with custom functions
>>
>> func CustomTemplateExecute(res http.ResponseWriter, req *http.Request, 
>> templateName string, data map[string]interface{}) {
>> // Append common templates and data structs and execute template
>> var funcMap = template.FuncMap{
>> "humanSize": humanSize,
>> }
>> t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE, 
>> templates.NOTIFICATIONS, templates.TICKER, templateName)
>> if len(data) == 0 {
>> data = make(map[string]interface{})
>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>> } else {
>> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
>> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
>> }
>> t.Execute(res, data)
>> }
>>
>> func humanSize() string {
>> return "Hello"
>> }
>>
>> I get template is empty error, i have tried giving a name to template.new 
>> and its the same error.
>> Any help is appreciated, thank you !
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] template Funcs with ParseFile and Execute

2017-03-25 Thread Yves Junqueira
Your ParseFiles call has a "templateName" argument in it. The ParseFiles
function only takes file paths, not template names.

And templates.New takes a template name, not a file path.

Hope this helps.

On Sat, Mar 25, 2017 at 9:14 AM, priyank pulumati <
pulumati.priy...@gmail.com> wrote:

> hello,
> im building a go web app and facing an issue with Executing templates with
> custom functions
>
> func CustomTemplateExecute(res http.ResponseWriter, req *http.Request,
> templateName string, data map[string]interface{}) {
> // Append common templates and data structs and execute template
> var funcMap = template.FuncMap{
> "humanSize": humanSize,
> }
> t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE,
> templates.NOTIFICATIONS, templates.TICKER, templateName)
> if len(data) == 0 {
> data = make(map[string]interface{})
> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
> } else {
> data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
> }
> t.Execute(res, data)
> }
>
> func humanSize() string {
> return "Hello"
> }
>
> I get template is empty error, i have tried giving a name to template.new
> and its the same error.
> Any help is appreciated, thank you !
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] template Funcs with ParseFile and Execute

2017-03-25 Thread priyank pulumati
hello,
im building a go web app and facing an issue with Executing templates with 
custom functions

func CustomTemplateExecute(res http.ResponseWriter, req *http.Request, 
templateName string, data map[string]interface{}) {
// Append common templates and data structs and execute template
var funcMap = template.FuncMap{
"humanSize": humanSize,
}
t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE, 
templates.NOTIFICATIONS, templates.TICKER, templateName)
if len(data) == 0 {
data = make(map[string]interface{})
data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
} else {
data["user"], _ = store.GetUser(context.Get(req, "userid").(string))
data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string))
}
t.Execute(res, data)
}

func humanSize() string {
return "Hello"
}

I get template is empty error, i have tried giving a name to template.new 
and its the same error.
Any help is appreciated, thank you !

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] template Inheritance

2016-11-16 Thread Manlio Perillo
I'm trying to use the new block action in the template package but I'm not 
sure to understand how it should be use.

What I would like to do is something like template inheritance support in 
Jinja templating:
http://jinja.pocoo.org/docs/dev/templates/#template-inheritance


Thanks  Manlio

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.