-
-
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
Add a widget mechanism to Hugo #2687
Conversation
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 last commit defines the variables that can be accessed in the widget's template. The context is:
|
When #2649 is done, it may be more clear what a And please don't ask me how do we do that? I have plenty on my plate at the moment, and this isn't priority. |
This is nice. Thank you for explaining this about widgets as nodes. BTW, when I ask something in the forum, please consider that I am asking it to the whole community, not especially to you in particular. I will be happy if we discuss together (indeed !), but will not be offended if it happens that you do not answer to me. We are with you, and all together here! Anyway I know you are doing a hard work on Hugo nodes and this is extraordinary! I am looking forward how all this will become. |
Good, let us keep the discussion there. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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, nor documentation.
Discussion is most welcome!
/widgets
. It should look like this:Note that the name
widget.html
is mandatory. Currently the context is the content of the config parameterwidgets.[mywidgetarea].[mywidget].options
. Variables are accessible with.content
for a text widget like the following and as described in the config below.widgets
variable describing widgets inside widget areas:widgets
call. This can be done like this:{{ widgets "sidebar" . }}
.{{% widgets "showcase" %}}
Fixes #2683
See #2535