<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Empty group field count/length confusion? in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404660#M20823</link>
    <description>&lt;P&gt;The issue might be that you're missing an id. It can be the same as the name so&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"id" : "sub_links",
"name": "sub_links",
..&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm also not sure why you're using object.sub_links instead of module.sub_links. Is the sub_links field group a nested inside another field group with the id of 'object'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 17:45:55 GMT</pubDate>
    <dc:creator>piersg</dc:creator>
    <dc:date>2021-01-29T17:45:55Z</dc:date>
    <item>
      <title>Empty group field count/length confusion?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404340#M20808</link>
      <description>&lt;P&gt;I have created a module with the following nested field :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
... other fields...
},
{
  "type": "group",
  "name": "sub_links",
  "label": "Second Level Links",
  "expanded": true,
  "occurrence" : {
    "min" : null,
    "max" : null,
    "sorting_label_field" : null,
    "default" : 0
  },
  "children": [
    ...
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my hubl template I'd like to see if there have been any sub_links added and if so, iterate on them. My issue however is that the hubl tag code (object is the instance that would have the sub_links field):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{{object.sub_links|length}}&lt;/LI-CODE&gt;&lt;P&gt;This always seems to display a length of "4" anytime I would expect it to be "0" (empty). If I add any items in the CMS, the above code would then show the correct count. For some reason an empty array is displaying a non-zero length. it's also interesting that "4" corresponds with the number of available fields on a single group item (fields on the sub_link item). Is there something wrong with the way I'm using length or setting up the group field? I just want to determine if the group field has contents or not.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 21:30:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404340#M20808</guid>
      <dc:creator>RDouglas</dc:creator>
      <dc:date>2021-01-28T21:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Empty group field count/length confusion?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404570#M20819</link>
      <description>&lt;P&gt;You can use the &lt;A href="https://developers.hubspot.com/docs/cms/hubl/operators-and-expression-tests#iterable" target="_blank" rel="noopener"&gt;iterable expression test&lt;/A&gt; to check if something can be iterated over, see if that works instead of the length filter e.g.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if object.sub_links is iterable %}
  {% for link in object.sub_links %}
  ..etc
{% endif %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 14:42:42 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404570#M20819</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2021-01-29T14:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Empty group field count/length confusion?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404623#M20821</link>
      <description>&lt;P&gt;That doesn't work since it seems the problem is that the sub_links object is being created with an single empty instance (making sub_links iterable) even though the CMS content editor hasn't added anything. Is there an issue with how I've set up the group occurence field that would be causing this?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 16:06:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404623#M20821</guid>
      <dc:creator>RDouglas</dc:creator>
      <dc:date>2021-01-29T16:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Empty group field count/length confusion?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404660#M20823</link>
      <description>&lt;P&gt;The issue might be that you're missing an id. It can be the same as the name so&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"id" : "sub_links",
"name": "sub_links",
..&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm also not sure why you're using object.sub_links instead of module.sub_links. Is the sub_links field group a nested inside another field group with the id of 'object'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 17:45:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404660#M20823</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2021-01-29T17:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Empty group field count/length confusion?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404693#M20825</link>
      <description>&lt;P&gt;Looks like "is iterable" actually did the trick, I just also had an incorrect assumption in my template code. Still confused why the length is inaccurate though...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're correct, the 'sub_links' group is nested. The 'object' key is just an artifact of trying to consolidate my code for this post&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt; The actual code would be something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% for link in module.links %}
  {% set has_children = link.sub_links is iterable %}
  {% if has_children %}
    {% set children_class = 'item-has-children' %}
  {% endif %}
  ... template html code ...
{% endfor %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see my mistake was that I was assuming 'has_children' would be destroyed for every iteration of the loop, but it looks like once it gets set it just stays there until explicitly unset. Just so happens that the first 'link' had set 'has_children' to true.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, thanks for the help!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 19:03:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Empty-group-field-count-length-confusion/m-p/404693#M20825</guid>
      <dc:creator>RDouglas</dc:creator>
      <dc:date>2021-01-29T19:03:48Z</dc:date>
    </item>
  </channel>
</rss>

