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

hooks: hand data to a filter hook and return transformed data #20

Open
davidsneighbour opened this issue Jul 28, 2022 · 2 comments
Open
Assignees
Labels
module:hooks type:documentation Improvements or additions to docs. type:enhancement New enhancements and features.

Comments

@davidsneighbour
Copy link
Owner

WordPress filter feature for GoHugo basically. Hand data to a filter(-hook) partial and if a filter partial exists for that filter term then run the data through it and return whats returned or the data unchanged.

@davidsneighbour davidsneighbour self-assigned this Jul 28, 2022
@davidsneighbour davidsneighbour changed the title Filters: hand data to a filter hook and return transformed data hugo-hooks: hand data to a filter hook and return transformed data Mar 30, 2023
@davidsneighbour davidsneighbour transferred this issue from davidsneighbour/hugo-hooks Mar 30, 2023
@davidsneighbour davidsneighbour changed the title hugo-hooks: hand data to a filter hook and return transformed data hooks: hand data to a filter hook and return transformed data Mar 3, 2024
@davidsneighbour
Copy link
Owner Author

Call:

{{- $filteredValue := partials.Include "func/filter.html" ( collections.Dictionary 
                                            "filter" "filtername" 
                                            "context" . ) -}}

The required parameter is filter with the filter name. everything else depends on the filter and its documentation.

Configuration (copy paste from the current hooks docs):

Module based hooks (plugin hooks)

In params.toml (or under the [params] section of the configuration) add a table array as such:

[[dnb.hooks.filters.namespace.filtername]]
file = "partial path"
weight = "integer"
cached = "boolean/string"

# proper sample
[[dnb.hooks.filters.namespace.urlfilter]]
file = "func/urlfilter.html"
weight = 100
cached = false

Notes:

  • filtername without cached at the end. The filter must exist and be called by the calling template so that this filter is added. If the filtername does not exist, this filter will be ignored.
  • weight is used for sorting filter. Please leave this out to have the filter run in the order it is added. the default weight is 0. Use this only if you want a filter run before or after others.
  • cached is either a boolean defining if the result of the filter is cached per page or run every time it's called or a string. in that case, it is cached with this string as an identifier. This string might be a simple string, which will cache the result globally (NOT per page), or it might contain a %random%, which will be replaced with a random string.

Note that the cached option is a work in progress. I'll need to find ways to cache, for instance, according to section. This might change over time.-

@davidsneighbour
Copy link
Owner Author

WIP: see 5669337 and 36a03c3

@davidsneighbour davidsneighbour added state:unconfirmed This issue needs to be reproduced. module:hooks type:documentation Improvements or additions to docs. type:enhancement New enhancements and features. and removed enhancement state:unconfirmed This issue needs to be reproduced. labels Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:hooks type:documentation Improvements or additions to docs. type:enhancement New enhancements and features.
Projects
None yet
Development

No branches or pull requests

1 participant