Problem
My problem is: I created a new theme for mautic and I have header and footer in the theme. I want to show header and footer for my preference page and also for a simple text message when I click on the unsubscribe link of the theme.
For the simple text, it works fine but for the preference page, it shows double header and footer.
Implementation
I have header and footer in my base.html.twig file. So, it can show unsubscribe message and preference page with header and footer.
Is there anybody who created theme with header and footer for showing message and also to show them in preference page ?
Hello @joeyk . If you know about this issue or any other person then please inform me. I really need a solution for this issue. I didnot get any response from the community about this issue. I noticed that most of the poeple don’t even use preference pages for unsubscribe links of emails or they do not use header and footer to follow them as standard. Please try something for unsubscribe page as header and footer. I think there is bug in mautic.
Issue:
If we place the header and footer in base.html.twig file then it will show two headers and footers in the preference page. This is really a bug in mautic. Please consider this as bug. It is really getting complicated to find workaround for this.
joeyk
April 14, 2023, 7:47am
3
Hi, sorry for the trouble. Im not sure what do you mean as header and footer. Can you post an example page here?
sure @joeyk . I am preparing a small description with steps that will explain how you can reproduce the issue.
@joeyk You can try these steps to reproduce this issue. I also created a bug on github for this link is given below :
opened 10:19AM - 14 Apr 23 UTC
bug
needs-triage
### Mautic Version
4.4.x series
### PHP version
8.0.28
### What brow… sers are you seeing the problem on?
_No response_
### What happened?
**Problem**
My problem is: I created a new theme for mautic and I have header and footer in the base file of the theme. when I click on the unsubscribe link of the theme, It shows double header and footer.
For the simple text, it works fine but for the preference page, it shows double header and footer.
**Implementation**
I have a header and footer in my base.html.twig file. So, it can show an unsubscribe message and preference page with header and footer.
Is there anybody who created the custom theme with header and footer for showing message and also to show them in preference page ?
### How can we reproduce this issue?
You can try these steps to reproduce this issue.
1. select any theme (legacy or grapesjs) from mautic **(I will select for now grapesjs theme)** and download it.
2. open it in any code editor.
3. Open config.json file and change the things according to your testing or just copy the given below code and paste it.
```
{
"name": "mautic Test DoubleCodeIssue",
"author": "Mautic team",
"authorUrl": "https://mautic.org",
"builder": ["grapesjsbuilder"],
"features": [
"email",
"page"
]
}
```
4. open base.html.twig file and place the code is given below and save it.
```
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if page is defined %}
<title>{pagetitle}</title>
<meta name="description" content="{pagemetadescription}">
{% endif %}
{% block stylesheets %}{% endblock %}
{{ outputHeadDeclarations() }}
</head>
<body>
{{ outputScripts('bodyOpen') }}
<p>This is the base file</p>
{% block content %}{% endblock %}
{{ outputScripts('bodyClose') }}
</body>
</html>
```
5. Open message.html.twig file and place this given below code and save it.
```
{% extends ":"~template~":base.html.twig" %}
{% block stylesheets %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" />
{% endblock %}
{% block content %}
<div>
This is message file......
{{ message|raw }}
{% if content is defined %}
<div>{{ content|raw }}</div>
{% endif %}
</div>
{% endblock %}
```
6. Open page.html.twig file and place this code the given below code and save it.
```
{% block content %}
<div data-section-wrapper="1">
<center>
<table data-section="1" style="width: 600;" width="600" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<div data-slot-container="1" style="min-height: 30px">
<div data-slot="text">
<br>
<h2>Hello there!</h2>
<br>
This is Page File...
<br>
<br>
<br>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</center>
</div>
{% endblock %}
```
7. Now save this theme and make a .zip file.
8. Go to mauitc and click on top right corner setting icon and click on "Themes" and click on "Install" to upload theme.
09. When theme is uploaded, now on left side on mautic, go to components -> Landing Pages and click on "+ New" and then select the uploaded theme and then go to builder and paste "{saveprefsbutton}" this text just under the text "This is Page File..." save this landing page(Note: "Set as preference center page" should be "Yes").
10. Now create a new email in mautic with New 'Segment Email' and select the uploaded theme.
11. In the same email builder select "Contact segment" (or create any test segment with test contact) and select "Preference center page", which you created in step 6.
12. Click on top right corner setting icon and click on "Configuration". you will see on left side the list of settings, click on ""Email settings". Here you will see at the end "Unsubscribe Settings". In "Unsubscribe Settings" please mark following fields to "Yes" :
- Show contact preference settings
- Show contact segment preferences
you can select all of them but at least click "Yes" for these two and then save these configuration settings.
13. Now click on "save and close" button and then click on "send".
14. After sending the email check the email you just send. If you didnot received the emial then you can go to the specific email in mautic and click on "Contacts" thier will be list of all contacts, click on any contact and click on the "Event Name" with the email you just sent.
15. Now click on the unsubscribe link of this email. You will the result as given below :
<img width="664" alt="image" src="https://user-images.githubusercontent.com/85757348/232017919-55369ede-6446-4f84-9759-063ad9cb2a1b.png">
Why it is showing double base file here and also why it is showing message file here.
### Desired output
it should only show the one base file and only the page file here.
### Code of Conduct
- [X] I confirm that I have read and agree to follow this project's Code of Conduct
select any theme (legacy or grapesjs) from mautic (I will select for now grapesjs theme) and download it.
open it in any code editor.
Open config.json file and change the things according to your testing or just copy the given below code and paste it.
{
"name": "mautic Test DoubleCodeIssue",
"author": "Mautic team",
"authorUrl": "https://mautic.org",
"builder": ["grapesjsbuilder"],
"features": [
"email",
"page"
]
}
open base.html.twig file and place the code is given below and save it.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if page is defined %}
<title>{pagetitle}</title>
<meta name="description" content="{pagemetadescription}">
{% endif %}
{% block stylesheets %}{% endblock %}
{{ outputHeadDeclarations() }}
</head>
<body>
{{ outputScripts('bodyOpen') }}
<p>This is the base file</p>
{% block content %}{% endblock %}
{{ outputScripts('bodyClose') }}
</body>
</html>
Open message.html.twig file and place this given below code and save it.
{% extends ":"~template~":base.html.twig" %}
{% block stylesheets %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" />
{% endblock %}
{% block content %}
<div>
This is message file......
{{ message|raw }}
{% if content is defined %}
<div>{{ content|raw }}</div>
{% endif %}
</div>
{% endblock %}
Open page.html.twig file and place this code the given below code and save it.
{% block content %}
<div data-section-wrapper="1">
<center>
<table data-section="1" style="width: 600;" width="600" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<div data-slot-container="1" style="min-height: 30px">
<div data-slot="text">
<br>
<h2>Hello there!</h2>
<br>
This is Page File...
<br>
<br>
<br>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</center>
</div>
{% endblock %}
Now save this theme and make a .zip file.
Go to mauitc and click on top right corner setting icon and click on “Themes” and click on “Install” to upload theme.
When theme is uploaded, now on left side on mautic, go to components → Landing Pages and click on “+ New” and then select the uploaded theme and then go to builder and paste “{saveprefsbutton}” this text just under the text “This is Page File…” save this landing page(Note: “Set as preference center page” should be “Yes”).
Now create a new email in mautic with New ‘Segment Email’ and select the uploaded theme.
In the same email builder select “Contact segment” (or create any test segment with test contact) and select “Preference center page”, which you created in step 6.
Click on top right corner setting icon and click on “Configuration”. you will see on left side the list of settings, click on "“Email settings”. Here you will see at the end “Unsubscribe Settings”. In “Unsubscribe Settings” please mark following fields to “Yes” :
Show contact preference settings
Show contact segment preferences
you can select all of them but at least click “Yes” for these two and then save these configuration settings.
Now click on “save and close” button and then click on “send”.
After sending the email check the email you just send. If you didnot received the emial then you can go to the specific email in mautic and click on “Contacts” thier will be list of all contacts, click on any contact and click on the “Event Name” with the email you just sent.
Now click on the unsubscribe link of this email. You will the result as given below :
Why it is showing double base file here and also why it is showing message file here.
Desired output
it should only show the one base file and only the page file here.
dirk_s
April 15, 2023, 11:29am
6
Should be mentioned, that this might be the root cause:
opened 10:04PM - 08 Mar 21 UTC
closed 11:15PM - 03 Nov 21 UTC
T1
bug
landing-pages
stale
[//]: # ( Invisible comment:
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII… I
Before you create the issue:
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
Search for similar report among other reported issues.
Learn how to troubleshoot at https://www.mautic.org/docs/en/tips/troubleshooting.html
Use drag&drop to attach images or other files )
## Bug Description
I setup a custom preference center landing page. It is published with a template in code mode and is in language fr. I send an email where I have assigned this preference center landing page to it. The email is in language fr and is using the template blank. When I click on the unsubscribe link. I see the template of my landing page encapsulated in the `message.html.twig` extends the `base.html.twig` templates of the blank template. Moreover, a custom body and html header tags are added to the template.
The generated HTML :
```html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" />
<script data-source="mautic">
...
</script>
</head>
<body>
<div>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
my preference center landing page code mode content
</body>
</html>
</body>
</html>
```
I should be able to have a custom template for my custom landing page which is not linked to the template of the email I access the page from and without any modification done by mautic.
| Q | A
| --- | ---
| Mautic version | 3.3.1
| PHP version | 7.3.27
| Browser | Chrome
### Steps to reproduce
1. Setup a custom preference center page with template in code mode
2. Send an email with template blank and the previous preference center page assigned to this email
3. Click on the unsubscribe link in the email
### Log errors
No errors
I have tracked it here :
In [PublicControllerL242](https://github.com/mautic/mautic/blob/37ed5ee87900522c888b09ed3857ad0452fb33df/app/bundles/EmailBundle/Controller/PublicController.php#L242) :
```php
$event = new PageDisplayEvent($html, $prefCenter, $params);
$this->get('event_dispatcher')->dispatch(PageEvents::PAGE_ON_DISPLAY, $event);
$html = $event->getContent();
```
Listeners on this event are modifying the custom code of the preference center landing page. This is not the most troublesome part. It could stay as it is. However, the fact that it reuses the email template when we are in `mautic as code` template mode for the preference center is troublesome :
```php
// here $template is the one from the email from which we clicked on the unsubscribe link.
$contentTemplate = $this->factory->getHelper('theme')->checkForTwigTemplate(':'.$template.':message.html.php');
///...
$viewParams = [
'email' => $email,
'lead' => $lead,
'template' => $template,
'message' => $message,
];
return $this->render($contentTemplate, $viewParams);
```
I can propose a PR if you point me in the correct direction you would like this behavior to be changed/fixed. Maybe something like if custom preference center page is enabled and is a `mautic_as_code` template, override `$contentTemplate` to use a dedicated `empty.html.twig` template which just print `{{ message|raw }}`.
[//]: # ( Invisible comment:
Please check for related errors in the latest log file in [mautic root]/app/log/ and/or the web server's logs and post them here. Be sure to remove sensitive information if applicable. )