-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Dynamic call to template: partial call with prefix #2683
Labels
Comments
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
Nov 12, 2016
You can now call a partial template with a prefix by doing this: ``` { partial $SomePartialName $SomePrefix . }} ``` Fixes gohugoio#2683
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
Nov 13, 2016
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
Nov 13, 2016
Here is a first attempt to get widgets into Hugo. General tests are ok on my dev environment, but I have not already written tests for widgets. 1. Create a site 2. Create a widget directory inside `/widgets`. It should look like this: ``` widgets/ └── text ├── layouts │ └── widget.html └── README.md ``` Note that the name `widget.html` is mandatory. *Currently the context is the content of the config parameter `widgets.[mywidgetarea].[mywidget].options`*. Variables are accessible with `.content` for a text widget like the following and as described in the config below. ``` {{- if isset . "content" -}} {{- .content | safeHTML -}} {{- else -}}<pre>Here is a text widget, but there is nothing to print. Please define options.content inside every text widget in your config.</pre> {{- end -}} ``` 3. Configure your site with a `widgets` variable describing widgets inside widget areas: ``` widgets: sidebar: - type: text options: content: "<h1>IT WORKS from config</h1>" parser: html showcase: - type: text options: content: "Here lies a showcase." footer: - type: text options: content: "Powered by Hugo with widgets." foo: bar ``` 4. Create a template using the `widgets` call. This can be done like this: `{{ widgets "sidebar" . }}`. 5. Create content. You can also use the widget's shortcode: `{{% widgets "showcase" %}}` 6. Build and enjoy. - Currently the widgets' context is only the content of the config variable. We should add a wider context (easy). - I have not studied the impact on performances. - Else? Fixes gohugoio#2683 See gohugoio#2535
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
May 2, 2017
Here is a first attempt to get widgets into Hugo. General tests are ok on my dev environment, but I have not already written tests for widgets. 1. Create a site 2. Create a widget directory inside `/widgets`. It should look like this: ``` widgets/ └── text ├── layouts │ └── widget.html └── README.md ``` Note that the name `widget.html` is mandatory. *Currently the context is the content of the config parameter `widgets.[mywidgetarea].[mywidget].options`*. Variables are accessible with `.content` for a text widget like the following and as described in the config below. ``` {{- if isset . "content" -}} {{- .content | safeHTML -}} {{- else -}}<pre>Here is a text widget, but there is nothing to print. Please define options.content inside every text widget in your config.</pre> {{- end -}} ``` 3. Configure your site with a `widgets` variable describing widgets inside widget areas: ``` widgets: sidebar: - type: text options: content: "<h1>IT WORKS from config</h1>" parser: html showcase: - type: text options: content: "Here lies a showcase." footer: - type: text options: content: "Powered by Hugo with widgets." foo: bar ``` 4. Create a template using the `widgets` call. This can be done like this: `{{ widgets "sidebar" . }}`. 5. Create content. You can also use the widget's shortcode: `{{% widgets "showcase" %}}` 6. Build and enjoy. - Currently the widgets' context is only the content of the config variable. We should add a wider context (easy). - I have not studied the impact on performances. - Else? Fixes gohugoio#2683 See gohugoio#2535
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
May 13, 2017
Here is a first attempt to get widgets into Hugo. General tests are ok on my dev environment, but I have not already written tests for widgets. 1. Create a site 2. Create a widget directory inside `/widgets`. It should look like this: ``` widgets/ └── text ├── layouts │ └── widget.html └── README.md ``` Note that the name `widget.html` is mandatory. *Currently the context is the content of the config parameter `widgets.[mywidgetarea].[mywidget].options`*. Variables are accessible with `.content` for a text widget like the following and as described in the config below. ``` {{- if isset . "content" -}} {{- .content | safeHTML -}} {{- else -}}<pre>Here is a text widget, but there is nothing to print. Please define options.content inside every text widget in your config.</pre> {{- end -}} ``` 3. Configure your site with a `widgets` variable describing widgets inside widget areas: ``` widgets: sidebar: - type: text options: content: "<h1>IT WORKS from config</h1>" parser: html showcase: - type: text options: content: "Here lies a showcase." footer: - type: text options: content: "Powered by Hugo with widgets." foo: bar ``` 4. Create a template using the `widgets` call. This can be done like this: `{{ widgets "sidebar" . }}`. 5. Create content. You can also use the widget's shortcode: `{{% widgets "showcase" %}}` 6. Build and enjoy. - Currently the widgets' context is only the content of the config variable. We should add a wider context (easy). - I have not studied the impact on performances. - Else? Fixes gohugoio#2683 See gohugoio#2535
lebarde
added a commit
to lebarde/hugo
that referenced
this issue
Nov 26, 2017
Here is a first attempt to get widgets into Hugo. General tests are ok on my dev environment, but I have not already written tests for widgets. 1. Create a site 2. Create a widget directory inside `/widgets`. It should look like this: ``` widgets/ └── text ├── layouts │ └── widget.html └── README.md ``` Note that the name `widget.html` is mandatory. *Currently the context is the content of the config parameter `widgets.[mywidgetarea].[mywidget].options`*. Variables are accessible with `.content` for a text widget like the following and as described in the config below. ``` {{- if isset . "content" -}} {{- .content | safeHTML -}} {{- else -}}<pre>Here is a text widget, but there is nothing to print. Please define options.content inside every text widget in your config.</pre> {{- end -}} ``` 3. Configure your site with a `widgets` variable describing widgets inside widget areas: ``` widgets: sidebar: - type: text options: content: "<h1>IT WORKS from config</h1>" parser: html showcase: - type: text options: content: "Here lies a showcase." footer: - type: text options: content: "Powered by Hugo with widgets." foo: bar ``` 4. Create a template using the `widgets` call. This can be done like this: `{{ widgets "sidebar" . }}`. 5. Create content. You can also use the widget's shortcode: `{{% widgets "showcase" %}}` 6. Build and enjoy. - Currently the widgets' context is only the content of the config variable. We should add a wider context (easy). - I have not studied the impact on performances. - Else? Fixes gohugoio#2683 See gohugoio#2535
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello everyone,
If I am not wrong, for now the only way to dynamically call a template is to use the
partial
call, because Golang templates do not permit to do it with the basetemplate
call.For widgets we need to call other templates, so it would be great if we had a way to set a prefix to partials.
That could be done with a
{{ partial $SomeDynamicName (dict "prefix" "myprefix" "context" .) }}
. Then insidetpl/template.go
we test if theprefix
index is set.What do you think about that?
The text was updated successfully, but these errors were encountered: