FACE Templating, Jinja, Sorting, Replacing, and dictsort, and natural sort

FACE Templating, Jinja, Sorting, Replacing, and dictsort, and natural sort

Hello,

After some research it looks like Face is a derivative of python's Jinja templating system. 

This is great in the sense that there is actually some rather comprehensive documentation and examples online that can loosely be used to diagnose some issues in your own Face code, but there seem to be enough deviations from Jinja to occasionally make it a little aggravating.

With this in mind, some experimenting has led me to discover two undocumented filters that are quite useful for those using Face.  (I imagine there are probably others):  

The Sort Filter:

The following appears to work as an undocumented "sort" filter:

{% sorted_values = presorted_values | sort(attribute="value") %}


This would appear to corollate to the functionality in Jinja's implementation as described here:


The Replace Filter:

Another is the "replace" filter.  The following code works:

{% sorted_options = sorted_options | replace("}{","},{") %}


This would appear to corollate to the functionality in Jinja's implementation as described here:


The one however that has me a bit stumped is that the documented Face filter "dictsort" does not seem to do anything particularly useful insofar as I can tell - at least for my application.

In my case, I'm trying to sort key:value pairs in Zoho Commerce.  To be more specific, I'm trying sort a list of attribute options by the option name (or value) rather than the option id (which really is only useful in knowing the order in which a set of options was entered, as they're always assigned such that each one is id'd higher than the ones before).

The following is Zoho's documentation for Face's dictsort implementation:

 dictsort

This filter sorts the given values in dictionary, i.e., alphabetical order.

 

Syntax

{{ map_variable | dictsort }}

 

Example

{ % assign map2="{"ant" "black""dog" : "brown" "cat" : "yellow"} %}


{{ map2 | dictsort }}

 

Output

{ant=black, cat="yellow," dog="brown}


The description is a bit vague and doesn't really explain what dictsort does.  Based on the description alone, I might assume that it would be sorting based on the value.  This is not the case.  By looking at the example, it's actually sorting key/value combinations based on the key (the option id in my case) - not the value.

Hoping that the Jinja guide to provide some additional reference, it appears that the jinja dictsort filter should allow you to sort by value: 
{% for item in mydict|dictsort(false, 'value') %}
    sort the dict by value, case insensitive
Unfortunately, I can't seem to get this working in Face in similar fashion.

Given its usefulness - especially for applications related to Zoho Commerce, can Zoho please expand dictsort to more closely mirror the behavior of the Jinja implementation to support sorting based on values instead of keys?

Lastly, I'd like to ask that Zoho might consider implementing one other filter type.  There are several situations in which you might have options, product descriptions, or the like that are sequenced numerically.  For example, if I'm selling lightbulbs, my attributes might be something like: 

50 Watt
75 Watt
100 Watt

If I sorted these using a dictionary sort, they would end up as:

100 Watt
50 Watt
75 Watt

(This same problem is shown when sorting numeric skus in Inventory) 

This of course is because 1 sequentially comes before 5, but the sorting code doesn't recognize that the value 100 is greater than the value of 50.

It would be far better to have a "natural sort" filter.  If python is fact the backend for Face, the code shown here might be useful in doing do:


Thanks,
Bryan


    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • SEO for your Zoho Sites Website

                                                              Join our live webinar to learn how to use Zoho Sites' SEO tools to boost your website's ranking. Our product specialist will demonstrate everything you need to know about optimizing your web pages to make them search engine friendly. Register here for free: https://www.zoho.com/sites/webinars/
                                                            • Website Accessibility

                                                              I have two sites created in Zoho Sites which are both live. Some questions: 1. Are any of the template themes WCAG 2.1 AA compliant? 2. How do I change the format of a sub-heading in the header section? 3. Is there any way to add focus indication for
                                                            • Unveiling Zoho Sites 2.0 - A new dimension in website building

                                                              Dear Zoho Sites Users, We are thrilled to announce the launch of Zoho Sites 2.0 today! This refresh represents a significant step forward in the capabilities of Zoho Sites and is crucial for creating a lasting and positive impact on our customers' businesses.
                                                            • Visual Editor Webinar

                                                              Join our FREE live webinar to learn how to use the Zoho Sites Visual Editor to easily design your website. Our product specialist will demonstrate how this tool will help you customize your website to suit your requirements.  Register here: https://www.zoho.com/sites/webinars/
                                                            • Zoho Sites Webinar | Integrations

                                                              Join our FREE live webinar to learn how to integrate both Zoho and third-party products with your Zoho Sites website. Our product expert will demonstrate how to use these integrations to grow, manage, and retain the customers you bring in. Learn how to take your business forward and build stunningly robust and efficient websites. Register here: https://www.zoho.com/sites/webinars/


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • Generating Discount Coupons for Zoho Bookings

                                                                                                              Hi, Is there provision to generate Discount Coupons for appointment bookings? I could not see that in the settings and this is very much needed. Please suggest us. Thanks
                                                                                                            • How do I remove mail hosting?

                                                                                                              I have a problem, I can't remove mail hosting. I need to remove them to cancel my domain, but it's imposible to cancel or remove the mail hosting. Please I need help urgently to resolve this problem.   Thanks
                                                                                                            • Notes created in mobile app not syncing with web notebook

                                                                                                              I have created certain notes in a new notebook in mobile app. The new notebook is also created using mobile app and when I logged in through web I am unable to see notebook that I have created using mobile app. there is no trace of notes in which i have created in mobile app on the web even after days of creating in mobile app This is not the case vise-a-versa. the notes and note book created on web are accessible on mobile app on real time.  this is very inconvenient and big demotivating factor
                                                                                                            • Desk - CRM Integration: SPAM Contacts (Auto Delete)

                                                                                                              SPAM contacts is a useful feature, but when the CRM sync is used, it is very frustrating. When a contact is marked as SPAM on Desk, I wish to do the same on CRM. When a SPAM contact is deleted, I would like it deleted from CRM. The feature looks half-baked.
                                                                                                            • No more IMAP/POP/SMTP on free plans even on referrals with NO NOTICE

                                                                                                              Outraged. Just referred a colleague to use her domain (not posting it publicly here) to Zoho, just as I have other colleagues, clients, friends. Expected the exact same free plan features as I have and as everyone else I ever referred got. I was helping
                                                                                                            • Mac Thunderbird zoho e mail account issues

                                                                                                              I have issues with a user account on thunderbird e mail client who suddenly does not receive emails, when you click get messages we get an error "sending of password for user ......did not succeed, mail poppro.zoho.com responded service unavailable" after
                                                                                                            • PASSWORD

                                                                                                              Hello, I'm Joyce, my client used zoho for password sharing, he did share the canva but once I clicked on it it will not automatically log-in, instead I need to log-in again. My question is my boss log-in first to his gmail and use his gmail to log-in
                                                                                                            • Kaizen #195: Frequently Asked Questions on Bulk Read API and Bulk Write API

                                                                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                                                                            • admin problem

                                                                                                              i can't to reach for the panel that i will create another mail to our company account i have admin access but i can't reach the panel our Company name Scale point my mail asmaa@dcalepointhub.com please can you help me Thanks
                                                                                                            • 554 5.7.1 : Recipient address rejected: user [username] does not exist

                                                                                                              Hi, I mistakenly altered my shopify email settings (where my domain is managed), but immediately reverted them, however now I have a strange email issue. I can send emails just fine, but cannot receive them. I have tried all troubleshooting steps but
                                                                                                            • Legit email address?

                                                                                                              Hello, I received emails from zohoadmin@biznetvigator.com with a password expiry notice. is that a legitimate email?
                                                                                                            • SMTP Authentication Fails with App Password – “535 Authentication Failed” Error

                                                                                                              Hello, I'm trying to send transactional emails from my WordPress website using the WP Mail SMTP plugin with Zoho Mail (smtp.zoho.com on port 465 with SSL). I've created and used a Zoho Mail app-specific password for SMTP, and verified that: The email
                                                                                                            • Deluge script issue : Mismatch of data type expression. Expected BIGINT but found STRING

                                                                                                              I'm building a Zoho Creator form to take inputs for Email, Bootcamp Name, and Tag. If a record with the same Email + Bootcamp exists in a custom module (bootcampattendence), I want to update it by adding a new tag. If it doesn’t exist, I want to create
                                                                                                            • Survey end date extension

                                                                                                              Hi, Is there any way to extend the end date of my survey? I needed more time in finding respondents that is why I need to extend the end date of my survey. Help. Thanks
                                                                                                            • Problem with signature in a forwarded mail

                                                                                                              Dear All, In my email account I created a signature and I unchecked the 'Place signature above the quoted text for relies and forwards' My question is, when I am trying to forward an email, sometimes I need to insert my signature so I select it from the
                                                                                                            • Out of Office not working

                                                                                                              I have set up out of office on zoho mail, however, it does not reply to every mail sent to it. I have tested it by sending several test messages from multiple different email accounts, I will get a response to some of them, but not all of them this is
                                                                                                            • Error message that says only images and no text

                                                                                                              I filled out a template for a weekly newsletter with text and images throughout but when I click save and next an error message comes up that says "Campaign content has only images and no text" which is not true at all. I have no idea how to fix this issue and don't know where the problem is. 
                                                                                                            • Contacts Don't Always Populate

                                                                                                              I've noticed that some contacts can easily be added to an email when I type their name. Other times, a contact doesn't appear even though I KNOW it is in my contact list. It is possible the ones I loaded from a spreadsheet are not an issue and the ones
                                                                                                            • Cannot add zoho email to gmail acc

                                                                                                              I'm trying to set up my zoho mail to connect to my gmail acc but no matter what I try I always get this problem. What should I do now? Password is up-to-date. Authentication failed. Please check your username/password. [Server response: 535 Authentication
                                                                                                            • 553 Relaying disallowed - Invalid Domain

                                                                                                              I have this error "553 Relaying disallowed. Invalid Domain" when sending an email to any email address. But I still receiving email from other emails. I checked MX, DKIM, SPF and it's ok. Could you check and help? Thanks
                                                                                                            • Turn off Organization Contact List

                                                                                                              We need to be able to turn off the Organization Contact list for some of our staff. Once the Organization Contact list is turned off for a user, we would then like to be able to create a list of contacts on per user basis that would not be editable by
                                                                                                            • Unable to send massage Reason 553/ Relaying Disallowed. Invalid Domain

                                                                                                              Cant sed massages from my email. All massages from my domain received the same issue Unable to send massage Reason 553/ Relaying Disallowed. Invalid Domain
                                                                                                            • Kaizen #194 : Trigger Client Script via Custom buttons

                                                                                                              Hello everyone! Welcome back to another interesting and useful Kaizen post. We know that Client Scripts can be triggered with Canvas buttons and we discussed this with a use case in Kaizen#180. Today, let us discuss how to trigger Client Script when a
                                                                                                            • Make record entry more organized with the Sections component in Wizards

                                                                                                              Hello everyone! Wizards in Zoho CRM have always helped you break long record-detail pages or large sets of fields into multiple screens, making data entry smoother and more user-friendly. Now, we’re taking a major step forward with a new Sections component—giving
                                                                                                            • GSTIN Public Search API

                                                                                                              Does zohobooks have an api using which i can search GST numbers and get their details?
                                                                                                            • External @zoho.com mail stopped working today, yesterday no issues

                                                                                                              Hello, Over a sudden mail stopped being delivered to inbox. Domain is standard zoho.com worked no problem yesterday, today nothing in inbox. Sent several test emails from corporate account & from gmail.com, logs show acceptance by zoho mail server, but
                                                                                                            • Suggestion: Smart Purchasing Module for Zoho Inventory and Zoho Books

                                                                                                              Suggestion: Smart Purchasing Module for Zoho Inventory and Zoho Books As an active user of Zoho Inventory and Zoho Books, I’ve noticed that the suite already provides valuable tools for managing inventory, analyzing trends, and processing purchase orders.
                                                                                                            • Adding bank details to the contact through API

                                                                                                              How to add bank-related information to the contact while creating it using API? The account number needs to be encrypted before sending it through API but not sure how to encrypt and get those values. Please guide me in this.
                                                                                                            • average cost display

                                                                                                              Hello there, I'm using the average cost valuation method, and the cost price shown in the Items menu should reflect the latest WAC (Weighted Average Cost). However, it doesn't update automatically. Is there a way to display the current average cost without
                                                                                                            • Apple Mail issues

                                                                                                              Dear Sir or Madam, I am trying to configure my Zoho mail account to Apple Mail. It is not working. It seems to need more information (perhaps a path prefix?) than is shown in your tutorial (<www.zoho.com/mail/help/apple-mac-imap.html>). After plugging
                                                                                                            • Assistance Required for Migrating Data from Odoo Inventory to Zoho Inventory

                                                                                                              Hi Team, I previously used Odoo Inventory to manage my stock and transactions, and I’ve now moved to Zoho Inventory. I’d like to migrate my data from Odoo—including product details, stock, purchase, and vendor information- into Zoho Inventory for continuity
                                                                                                            • I need my entire Zoho Account (mail/organization) deleted!

                                                                                                              Hey! I used zoho for my email aaron@aaronglass.me with domain forwarding/mx all that. I got rid of the mx info on my godaddy account and still Google won't let me sign up with my aaron@aaronglass.me email. (I'm moving to Google for business) SO! I was
                                                                                                            • Error: "Invalid Element warehouse_id" when sending order to Zoho

                                                                                                              i'm getting the error "Invalid Element warehouse_id" when trying to send an order to Zoho via API. Has anyone faced this issue before? How can I fix it?
                                                                                                            • No way to sell individual and case units smoothly in Zoho

                                                                                                              Currently, Zoho Inventory handles inventory primarily at the case level, which can be challenging for businesses that frequently need to break down cases into individual units for retail sales or smaller shipments. Although Zoho Inventory currently supports
                                                                                                            • How to handle multiple languages (Resume parser, Job opening, job board, career site) ?

                                                                                                              We are looking to bring Zoho Recruit to a market that needs to support 2 languages. The first thing we need to make sure is that the Candidate be flag with the language they speak. This is easy enough make a custom field that as the desire languages.
                                                                                                            • Shipping Labels

                                                                                                              Hi, Can we generate Packing Labels for manual shipping same as the format as Airway Bill in zoho books or inventory?
                                                                                                            • Unit Measurement Sign,

                                                                                                              Dear Zoho Support Team, I hope you are doing well. We recently purchased Zoho Inventory based on recommendations of your team that “it would be a great fit for our Shopify operations”. However, we are currently facing several urgent issues that require
                                                                                                            • Leadchain into a custom module

                                                                                                              Hello ZOHO Community ! is it possible to put the leads collected by leadchain into a custom module instaed of leads module ? Best wishes Niels
                                                                                                            • Urgent: How to Bulk Upload Images in Zoho Inventory? Any Workarounds?

                                                                                                              We are currently onboarding 5,000+ items from Shopify into Zoho Inventory, but we’re struggling with the lack of a bulk image upload feature. Right now, we have to manually upload and assign images one by one, which is extremely time-consuming and inefficient.
                                                                                                            • Can I automatically update COGS and Inventory account when creating an item?

                                                                                                              I have been trying to get Zoho to update the other two fields when I update one (Sales Account, COGS account, and Inventory Account). I know this seems like not a huge time saver, but I am all about efficiency and being an independent taproom, I create
                                                                                                            • Next Page