Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass current view context to child/include template #19

Closed
jeevatkm opened this issue Mar 9, 2018 · 6 comments
Closed

How to pass current view context to child/include template #19

jeevatkm opened this issue Mar 9, 2018 · 6 comments

Comments

@jeevatkm
Copy link

jeevatkm commented Mar 9, 2018

@Joker I was trying your example program (https://github.com/Joker/jade/blob/master/example/jade.go) to see; how to integrate Jade library with aah framework.

I have observed following, please let me know. Am I understood correctly?

  1. <title>{{ pageTitle }}</title> is not valid go template syntax. Valid one is <title>{{ .pageTitle }}</title>
  2. And if condition too {{ if youAreUsingJade }}, valid one is {{ if .youAreUsingJade }}. Basically dot is missing before variable
  3. And pass on current context to child/sub template too; with dot notation like {{ template "withGo" . }} instead of {{ template "withGo" }}

Looking forward to your response.

@hengestone
Copy link

Why does it have to be valid go template syntax? These are jade templates, with go expressions.

@jeevatkm
Copy link
Author

@hengestone @Joker Yesterday I learned to use this library and Jade/Pug syntax. My understanding is -

  • We define templates in Jade (pug) form/syntax
  • Jade library transforms Jade template into Go Template

So I have tried given examples to see the behavior.

As you know, In Go template we define -

  • For template context variable with dot notation -> {{ .pageTitle }}
  • For template functions just mention function name ->{[ pageTitle }}
  • While including child/another template, for passing current context value; we have to use dot notation -> {{ template "withGo" . }}

Last night, I have tried further after submitting this issue and I was able to sorted out first 2 points and understood better. So we are good on first 2 points. Just updated this issue with strikethrough.

However, issue no. 3 remains. If you have an understanding please guide me.

Issue details:

When we define mixin and mention like this + withGo in the Jade template. Library produce this {{ template "withGo" }}; it is certainly a valid syntax. However it doesn't pass current view context variable to template withGo. Becuase for that syntax have to be with dot notation at the end {{ template "withGo" . }}

@jeevatkm jeevatkm changed the title It seems like not a valid go template variables and pass on current context to template too How to pass current view context to child/include template Mar 10, 2018
@jeevatkm
Copy link
Author

May be I'm missing some piece of details to understand!!!

@jeevatkm
Copy link
Author

This example: https://github.com/Joker/jade/tree/master/example/jade_extends produces go template with passing view context further.

<!DOCTYPE html>                         
<html>                                  
    <head>                              
        {{ block "title" . }}           
            <title>Default title</title>
        {{ end }}                       
    </head>                             
    <body>                              
        {{ block "content" . }}         
        {{ end }}                       
    </body>                             
</html>                                 

This is suppose to happen for mixin too + withGo => {{ template "withGo" . }}

@Joker
Copy link
Owner

Joker commented Apr 18, 2018

You haven't to do it now.
At version 1.0 mixin, include and extend works directly with no translation into the Go templates.

@Joker Joker closed this as completed Apr 18, 2018
@jeevatkm
Copy link
Author

@Joker I will give it try and get back to you. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants