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

Liquid function to pull data from within template #97

Closed
apexdodge opened this issue Mar 26, 2023 · 3 comments
Closed

Liquid function to pull data from within template #97

apexdodge opened this issue Mar 26, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@apexdodge
Copy link
Contributor

There are use cases where it would be very beneficial to be able to make additional calls to pull content once you are rendering the template.

By the default, the data tied to the template is either a list view or a detail view of the item you are targeting. However, what if we want to add a a sidebar on the template that dynamically pulls content items, or maybe a dynamic header / footer nav. Currently, all these other elements would need to be hardcoded, or the developer would have to create their own fork and add in the functionality. It would be great if this was baked in functionality.

The problem is, I'm not 100% sure how to do this, research is needed.

I think we need to:

  1. Create some helper functions as described here: https://github.com/sebastienros/fluid#extensibility like get_content_item_by_id(...) and get_content_items(...)
  2. Add the functionality to RenderEngine.cs
    var context = new TemplateContext(entity, options);
    -- now we are already injecting IRelativeUrlBuilder, so in theory, if we are able to inject IMediator, then maybe we can make database calls?
@apexdodge apexdodge added the enhancement New feature or request label Mar 26, 2023
@apexdodge
Copy link
Contributor Author

This actually works, amazing Messing around, here's a sample:

{{ get_content_item_by_id(Target.Id).PublishedContent.content.Text }}<br/>
{% assign items = get_content_items('zBBZ9vQe90yDvUe7-jPsxQ', 'pages') %}
{{ items | json }}

Still WIP - I think the get_content_items functionality should work with the View's developer name instead of viewId, but almost there. Should also support pagination, but almost there. Can be done for v1.0.4.

@apexdodge apexdodge added this to the v1.0.4 milestone Mar 28, 2023
@apexdodge
Copy link
Contributor Author

Preferred

{{ get_content_item_by_id(Target.Id).PublishedContent.content.Text }}<br/>
{% assign items = get_content_items(ContentType='posts', Filter="contains(PrimaryField, 'Home')", PageSize=1) %}
{{ items | json }}

@apexdodge
Copy link
Contributor Author

To be released with v1.0.4

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

No branches or pull requests

1 participant