- Posts: 7
Question
Help with a custom Privacy Policy module
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
Firstly let me say how impressed I am by webtrees. It's a great package, and I'm looking forward to exploring more of my Family History, with its assistance. Thank you Greg for all your hard work in its development.
I want to learn more about developing my own modules, and have been trying to implement a custom "privacy policy" module. I want to keep the statement about cookies, but to provide more information on the website owner. I have been using ~/app/Module/PrivacyPolicy.php to assist in creating my own, but I find I am unable to work out how to access the $uses_analytics variable in the getFooter() function to pass to the view template to produce the appropriate comments relating to use of analytics.
Any guidance on this would be very much appreciated. Thank you
Please Log in or Create an account to join the conversation.
- Lars1963
-
- Offline
- Junior Member
-
- Posts: 249
Please Log in or Create an account to join the conversation.
- fisharebest
-
- Offline
- Administrator
-
The module uses this code to create a footer using a template file. The tempate files in webtrees have a .phtml extension. This is just my convention.
So, in the template file (resources/views/modules/privacy-policy/footer.phtml), two variables are available: $tree and $uses_analytics.
.phtml files are PHP scripts, so use these variables like any other PHP variable.
e.g.
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7

Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7
What I was trying to get at is how to access the current value for $uses_analytics prior to using it in this snippet from my attempt.
<?php //if ($uses_analytics) : ?>
This website uses cookies to learn about visitor behavior.
<?php // endif ?>
As you see, I've commented it out, but I would like to:set it prior to invoking footer.phtml so that it accurately reflects whether I've configured "analytics" in the web interface. All the attempts I've made so far have involved more and more complications, and I figured I was getting into too much of a mess so I thought I'd seek help. Thank you for your time, and again thank you for webtrees.
Please Log in or Create an account to join the conversation.
- fisharebest
-
- Offline
- Administrator
-
The first (in the module) shows how to set the variable.
The second (in the view/template) shows how to read it.
Maybe show the code you've got, and it might be clearer?
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7
Starting with a change to the example-footer module github.com/webtrees/example-module-footer and the code:
results in an error message that analyticsModules() is an undefined method.
Including the method leads to more errors, and more attempts on my part to address them, until I figured I must be missing something.
I'm now wondering whether I need to extend with ModuleAnalyticsInterface and use it and ModuleAnalyticsTrait in my source?
I'm going to try that later today, and if I'm unsuccessful, I will .zip up the code I'm working on and include it in another post.
Thanks.
Please Log in or Create an account to join the conversation.
- bertkoor
-
- Offline
- Platinum Member
-
- Greetings from Utrecht, Holland
github.com/fisharebest/webtrees/blob/0c5...Policy.php#L120-L137
It in turn depends on $this->module_service which gets its value via the constructor:
github.com/fisharebest/webtrees/blob/0c5...cyPolicy.php#L41-L53
Maybe you had better copied this whole module as an example rather than the vanilla footer example.
stamboom.BertKoor.nl runs on webtrees v2.2.1
Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7
I have done as you suggest, and taken a copy of the module ~/app/modules/PrivacyPolicy.php
Its constructor needs to have 2 parameters, $module_service and $user_service:
:
I assume these 2 parameters, $module_service and $user_service will be needed, so how should I set their values?.
I found 2 code snippets (in separate sources):
But I expect I need more than that.
Please Log in or Create an account to join the conversation.
- fisharebest
-
- Offline
- Administrator
-
When the webtrees code creates an instance of your module, it will provide these objects automatically.
It's a technique known as "dependency injection", and is common in PHP frameworks/applications.
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7
Thank you to Lars1963, fisharebest and bertkoor for their assistance along the way.

And thanks of course to Greg, and other webtrees developers for a great package!
Please Log in or Create an account to join the conversation.
- hermann
-
- Offline
- Elite Member
-
Hermann
Designer of the custom module "Extended Family"
webtrees 2.2.1 (all custom modules installed, PHP 8.3.12, MariaDB 10.6) @ ahnen.hartenthaler.eu
Please Log in or Create an account to join the conversation.
- bluenellie
-
Topic Author
- Offline
- New Member
-
- webtrees v2.2 / PHP 8.3 on VPS
- Posts: 7
Thank you! I was very relieved when I got it working!Gratulation! Could you share or show.your result with us?

As to sharing it, although I have been a programmer for many years, I am still very much a novice when it comes to webtrees, but for what it's worth, here is my code for the main module:
Please Log in or Create an account to join the conversation.