RaythaHQ / raytha

Raytha is a powerful CMS with an easy-to-use interface and fast performance. It offers custom content types, a template engine, and various access controls. It supports multiple storage providers and an automatically generated REST API. Upgrade your development workflow with Raytha.
MIT License
155 stars 30 forks source link

Custom liquid func for GetContentTypeByDeveloperName #113

Closed apexdodge closed 1 year ago

apexdodge commented 1 year ago

We should add a new custom liquid function for getting content type by developer name.

Example usage:

{% assign contentType = get_content_type_by_developer_name('posts') %}
{{ contentType | json }}

This would be very useful if you want to create dynamic sidebar menus for things like filtering and sorting by the different field types. Otherwise you have to hardcode the values.

To be added here: https://github.com/RaythaHQ/raytha/blob/d28475fda4ce56aa8166bf6f9785ae646f72f662/src/Raytha.Web/Services/RenderEngine.cs#L105

apexdodge commented 1 year ago

This code would pull out the categories field on the posts content type and loop through the choices in the drop down box and gets the developer name and outputs links accordingly.

{% assign contentType = get_content_type_by_developer_name('posts') %}
{% assign categoriesField = contentType.ContentTypeFields | where: "DeveloperName", "categories" | first %}
{{ contentType | json }}
<hr/>
{% for choice in categoriesField.Choices %}
    <a href="{{ PathBase }}/{{ category.DeveloperName }}">{{ choice.Label }}</a>
{% endfor %}