Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
Hi there,

Is there a way to show the count (number) of relations in a one to many relation mode

Thanks in advance,
Bert
Can you please give some code to understand your use case?
Image
where innovation meets technology
bertdepoortere wrote: Hi there,

Is there a way to show the count (number) of relations in a one to many relation mode

Thanks in advance,
Bert


In admin-panel?
Hi all,

I feel I need to explain a little bit more about what I would like to achieve.
Hopefully this example makes it clear what the intention is.
Thanks for the help

regards
Bert

Template dates.php
Code: Select all
<cms:template title='dates' clonable='1'>
     <cms:editable name='related_users' type='relation' masterpage='users/index.php' />
     <cms:editable name='related_project' type='relation' masterpage='projects.php' has='one' />
     <cms:editable name='date' type='text' />
     ...
</cms:template>

projects.php
Code: Select all
<cms:template title='projects' clonable='1'>
     ...
</cms:template>
<body>
<cms:reverse_related_pages masterpage='dates.php'>
     <cms:show date /> - <cms:show count-of-related-users />
     <!-- I want to show the number of users that are related with a date   -->
</cms:reverse_related_pages>
</body>
Hi,

I think the following should work -
Code: Select all
<cms:reverse_related_pages masterpage='dates.php'>
     <cms:show date /> -
     
     <!-- I want to show the number of users that are related with a date   -->
     No. of users: <cms:related_pages masterpage='users/index.php' count_only='1' />
</cms:reverse_related_pages>

Please let me know if it helps.
Hi KK,

Unfortunately this does not work, even if a date is not related to a crew member, the result of this is always 1, even if 1 or more crew members are related.

Regards
Bert
My apologies, Bert - <cms:related_pages> expects the name of the relation field as param (and not the masterpage as I mistakenly used in my code above).

Following code should work as expected -
Code: Select all
<cms:reverse_related_pages masterpage='dates.php'>
     <cms:show date /> -
     
     <!-- I want to show the number of users that are related with a date   -->
     No. of users: <cms:related_pages 'related_users' count_only='1' />
</cms:reverse_related_pages>

Hope this helps.
Hi KK,
KK wrote: Following code should work as expected -
Code: Select all
<cms:reverse_related_pages masterpage='dates.php'>
     <cms:show date /> -
     
     <!-- I want to show the number of users that are related with a date   -->
     No. of users: <cms:related_pages 'related_users' count_only='1' />
</cms:reverse_related_pages>

Hope this helps.

This is what i need! thanks!
Bert
You are welcome Bert :)
9 posts Page 1 of 1