CMS Development

RedFernWilson
Member | Gold Partner
Member | Gold Partner

Passing CRM object to module

SOLVE

Hi 

 

I have a custom module that i want to use on a dynamic page. The dynamic pages data source is an Event CRM object. When the event template renders i want to pass in the current event to a module as a parameter so i can use one of the event properties in my module. 

 

For example: event.html

{% set event = data_query.data.CRM.p_events %}
{% extends "./layouts/base.html" %}

{% block body %}

    {% include "./partials/event-header.html" %}

    <div class="my-lg">
        <div class="content-wrapper">
            <div class="flex flex-wrap gap-lg | lg:flex-nowrap lg:gap-xl | xl:gap-2xl">
                <div class="w-full lg:w-2/3">
                    {% include "./partials/event-body.html" %}

                    {% module "how_to_enter"
                        label="How to Enter"
                        path="../modules/how-to-enter"
                        event={
                            id: event.hs_object_id,
                            object_type: 'events'
                        }
                    %}


I am unsure how to pass in the CRM object to the "how_to_enter" module. I tried event=event and as a custom object like above but when i render the event in the module like so 

{{ module.event | pprint }}

This just equals "null".


The field "event" in the module is defined as a crmobject and is "locked: true" so it cant be set on the template itself.

 

Any idea as to what i am doing wrong? I cant find any documentation on passing values in the template for crmobject type module fields.

0 Upvotes
1 Accepted solution
DanielPicklo
Solution
Participant | Diamond Partner
Participant | Diamond Partner

Passing CRM object to module

SOLVE

Understood! Apologies for the question, but just want to make sure that the ID itself is making it out of the query you've got. Does {{ event.hs_object_id }} return anything at the template level/is it one of the properties that has been specified in your query? I'm sure you've got it, but just wanted to cross that out for sure.

 

The way that the CRM object field in your module should expect it is something like the following:

 

{% module "module name" path="module path", label="module label"
  event={
    id: event.hs_object_id
  }
%}

Which would make it relatively close to what you had the first time.

 

The odd part is that it would return as a null value when using "module.event|pprint" as it should output something similar to: 

(SizeLimitingPyMap: {id=123, object_type=null, properties={}})

even if the ID was recognized, but nothing was found to match it.

 

Another option to consider that may work, but could also complicate things, is to utilize "dynamic_page_crm_object.hs_object_id" if this is a dynamic CRM object page and if your query itself isn't handling any additional filtering. If that is the case, you could potentially use it directly in the module itself to define your event as a fallback if no event record has been manually selected!

 

Let me know if the above gets us any closer and we can go from there if not!

View solution in original post

4 Replies 4
DanielPicklo
Participant | Diamond Partner
Participant | Diamond Partner

Passing CRM object to module

SOLVE

Hello there!

I think the first thing I would check is that we are getting a value back at the template level for your "event" variable. The only way I was able to replicate this exact situation in my test account was when the ID that I was passing into the module field settings was not defined.

 

If you are getting a value back from your "event" at the template level, we'll want to make sure that it is something we can dot notate through. I'd imagine it should return as an object type by default, but you'll want to check that it isn't a single object within an array.

 

Let me know what you find and we can work on debugging things further!

RedFernWilson
Member | Gold Partner
Member | Gold Partner

Passing CRM object to module

SOLVE

Hi Daniel


Thank you for the response.

 

At template level i am getting back the "event" information from the graphql query, so i am able to output properties without issue on the template itself, so for example event.name will output via hubl in the template without issue. It is only when i pass this event to the module as a prop e.g. 

 

{% module "how_to_enter"
                        label="How to Enter"
                        path="../modules/how-to-enter"
                        event=event
                    %}

 

that when i "pretty print" the modules data from inside the module, i.e. {{ module | pprint }} the "event" property is null.

 

I wanted to try and use this way so i could pass the event object as a whole to the module. I havent yet tried to change the "event" field in the module to be a number, pass the ID to the module from the template like

 

{% module "how_to_enter"
                        label="How to Enter"
                        path="../modules/how-to-enter"
                        event=event.hs_object_id
                    %}

 

and then fetch the event again from the module. I didnt want to do this, in case it queries twice. First on template load and then on module.


Please let me know if you need any more information or if i can help any further to understand the issue.

 

Thanks again

 

 

0 Upvotes
DanielPicklo
Solution
Participant | Diamond Partner
Participant | Diamond Partner

Passing CRM object to module

SOLVE

Understood! Apologies for the question, but just want to make sure that the ID itself is making it out of the query you've got. Does {{ event.hs_object_id }} return anything at the template level/is it one of the properties that has been specified in your query? I'm sure you've got it, but just wanted to cross that out for sure.

 

The way that the CRM object field in your module should expect it is something like the following:

 

{% module "module name" path="module path", label="module label"
  event={
    id: event.hs_object_id
  }
%}

Which would make it relatively close to what you had the first time.

 

The odd part is that it would return as a null value when using "module.event|pprint" as it should output something similar to: 

(SizeLimitingPyMap: {id=123, object_type=null, properties={}})

even if the ID was recognized, but nothing was found to match it.

 

Another option to consider that may work, but could also complicate things, is to utilize "dynamic_page_crm_object.hs_object_id" if this is a dynamic CRM object page and if your query itself isn't handling any additional filtering. If that is the case, you could potentially use it directly in the module itself to define your event as a fallback if no event record has been manually selected!

 

Let me know if the above gets us any closer and we can go from there if not!

RedFernWilson
Member | Gold Partner
Member | Gold Partner

Passing CRM object to module

SOLVE

Hi Daniel


Sincerest apologies for my late reply. Thanks again for assiting with this.

 

Interestingly, i have been able to get this to work as you mentioned using

event={
  id: event.hs_object_id
}

but i have to create a fresh version of the module i.e. add a new one to the page with a different name so instead of {%module "name" %} its {%module "name_2" %} as an example. 

 

Unfortunately, the issue i have after this though is if i change any other field  on the module from the site editor it overrides and removes the event so therefore it is null again. Even if the event field itself is set to "locked" and therefore i would expect not affected by the editor changes as its expecting to be set at template level anyway.

 

Have you any idea of a workaround with this?

 

Thanks again
Adam

0 Upvotes