CMS Development

FMesina
Member

Custom date for index page sort order.

SOLVE

I need to use a custom update date for a blog post and use it for sorting in the list/index page .

 

I have 3 fields
1. show_custom_update_date toggle to show custom update date on a post.
2. updated_date is for the custom date if enabled.
3. sort_date is to pass the variable data to a module.

 

```
{% set effective_date = module.show_custom_update_date ? module.updated_date : content.publish_date %}

{% set module.sort_date = effective_date %}
<p>Sort Date: {{module.sort_date}}</p>

```


I see no data in the sort_date field when viewing the developer info of the post. How can this be achieve via Hubl?

What is the best way to achieve custom sorting for the index page?

Thank you. 

0 Upvotes
1 Accepted solution
SteveHTM
Solution
Guide | Partner
Guide | Partner

Custom date for index page sort order.

SOLVE

@FMesina - Based on your description, my guess here is that to set the custom data on each plog post you will need to use "export to template context" logic on the blog post. A recent write of of this is here:

https://community.hubspot.com/t5/CMS-Development/Making-a-blog-work-as-an-event-calendar-with-custom...

 

Good luck,

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature

View solution in original post

0 Upvotes
4 Replies 4
SteveHTM
Guide | Partner
Guide | Partner

Custom date for index page sort order.

SOLVE

@FMesina - the convention for references to the 'template context' variables is different in the blog listing template from that in the blog post template. I also see you have a module reference that I think is redundant.

 

Once you have a subset of posts you wish to list - in sorted format ideally, you will be able to work with teh extra data field as follows:

 

Hope that helps,

  {% for post in sorted %} 
    {% set extra_date = post.widgets.extra_date.body.date_choice %}
    ...

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
evaldas
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom date for index page sort order.

SOLVE

Hi @FMesina 

 

Looks like the issue is with this line:

 

{% set module.sort_date = effective_date %}

 

Anything that starts with "module." is coming from the inputs of the module and cannot be changed by HubL. In order for that line to work, it would need to be a simple variable.

 

{% set custom_sort_date = effective_date %}

<p>Sort Date: {{custom_sort_date}}</p>

 

If you want to pull data from the module into the blog listing page, I believe it will only allow pulling the input values (that start with "module", not the variables).

 

Assuming you want to pull the value for "updated_date", your code in the listing template would look something like this:

 

{{ content.widgets.module_XXXXXXXXXXXX.body.updated_date }}

 

The XXXXXXXXXXXX would be the numerical ID of that original blog post module.

 

Hope this helps!

 


✔️ Did this post help answer your query? Help the community by marking it as a solution.

0 Upvotes
SteveHTM
Solution
Guide | Partner
Guide | Partner

Custom date for index page sort order.

SOLVE

@FMesina - Based on your description, my guess here is that to set the custom data on each plog post you will need to use "export to template context" logic on the blog post. A recent write of of this is here:

https://community.hubspot.com/t5/CMS-Development/Making-a-blog-work-as-an-event-calendar-with-custom...

 

Good luck,

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
FMesina
Member

Custom date for index page sort order.

SOLVE

@SteveHTM

I have tried using 

 
{% set effective_date = module.show_custom_update_date ? module.updated_date : content.publish_date %}
{% text "effective_sorting_date" label="The sorting date", value="{{effective_date}}", export_to_template_context=True %}`
 
I see it in the post page as:
 
  "widget_data": {
    "module_172082412025471_effective_sorting_date": {
      "parent_widget_container": null,
      "label": "The sorting date",
      "value": 1722225600000,
      "export_to_template_context": true,
      "content_editable_values": [
        "value"
      ]
    }
  },

But it is not showing up in the blog list and its developer info. I tried using these.

 

{{ content.widgets.module_172082412025471_effective_sorting_date.body.value }}
{{ content.widgets.effective_sorting_date.body.value }}

Please share possible issues preventing from passing the data? Thank you

0 Upvotes