Hey @kosalaindrasiri,
while your answer has a few points, there are a few misleading information as well. Also it seems like it was Ai generated.
If this should be the case - Ai is not forbidden, but it should be mentioned that the post or parts of it were Ai generated. It just helps the community.
First of all:
there’s no
{% break %}
variable in HubL.
Jinja2 has one.
HubL is based on Jinja2, so Ai very often mistakenly confuses HubL with Jinja2, and while it can happen that pure Jinja2 code will work in HubSpot, putting this variable in the code you’re suggesting doesn’t make any sense.
Secondly:
unless you’re doing something like update, append etc. there’s no real use in adding
{% set row = none %}
to the code.
So why inflating the code unnecessarily?
Furthermore - besides being able to write
{{ row.business_outcome }}
what’s the reason of adding
{% set row = item %}
to the code?
{{ item.business_outcome }}
would work perfectly fine in this case.
Or simply just write
{% for row in rows %}
{% if row.resource_name == module.business_outcome_resource %}
{{ row.intro }}
{% endif %}
{% endfor %}
Last but not least, if there would be an update/append function in your suggested code, the initial “set” shouldn’t be “none” but something like
{% set row = {} %}
or
{% set row = [] %}
The if-statement part @Woodsy provided technically works.
It is - more or less - easy to handle and also extendable for future updates.
Can it be written completely different and optimized? Yes, but it’s the documented way of an if-statement and therefore a good starting point as nobody knows who will deal with this code in the future. There are many ways to achieve a desired outcome, but if an unexperienced developer will look at something like
{% set table = hubdb_table(123456789) %}
{% set hs_object_matcher = {
"Increase Sales" : "191295276975",
"Increase Loyalty" : "191349040224",
...
}
%}
{% for column_name, hubdb_col_id in hs_object_matcher.items() %}
{% if module.business_outcome_ressource == column_name %}
{% set row = hubdb_table_row(table, hubdb_col_id) %}
{% endif %}
{% endfor %}
^ just an example from my head to outline a potentially different way of writing the code; might not work
it might be super confusing to him/her. The machine, doesn’t really care.
So keeping the code as easy to understand for humans and clean as possible should always be a priority.
best,
Anton