Hi

The current set-up for linking content to a campaign (using macros and the 'Mailchimp campaign' Input format) is great, and seems to work well.

Initially, while using it I found that I had problems producing good output.

I make use of an admin theme in addition to my site's main (client facing) theme. When the content is built for insertion into a campaign, the default node.tpl.php template files are used from my admin theme, rather than my site's main theme.

This is partly good, because it means I can define a different set of templates for newsletter content - but ideally I think there should be a specific set of phptemplate files available from each site's main theme.

e.g.

mailchimp.tpl.php
mailchimp--<node>.tpl.php
mailchimp--<node>-<mailchimp-template>.tpl.php
mailchimp--<node>-<mailchimp-template>-<mailchimp-content-area>.tpl.php

Does this already exist, and if not could be added as a feature?

Comments

Rob_Feature’s picture

Status: Active » Closed (duplicate)

This is really due to the lack of theme functions (which is the first step to template files), which is in #936504: Add theme functions. Marking this as a duplicate of that one.

e0ipso’s picture

Title: Provide specific mailchimp--<node>.tpl.php files » Select theme to render entity macros
Status: Closed (duplicate) » Active

I think the important point here is that entities are turned into HTML using the current theme. Given that campaigns are added in admin/config/services/mailchimp/campaign/add Drupal renders them using admin theme.

HTML Mail module, and others, allow you to select the theme you want to use. This is specially relevant for campaign creation.

If we do that then the selecion of the template is based on the current rules. You could create a view mode for each desired visual representation of the entity and add a theme suggestion to select a custom template (maybe to use tables for complex layouts). You might also use Display Suite for the last part.

basvredeling’s picture

Version: 7.x-2.x-dev » 7.x-3.1
Issue summary: View changes

This is still an issue in 3.1... The default use case as described is that nodes inserted with an entity lookup are rendered with the admin theme. I'd reckon there are few use cases where you send a news letter to subscribers rendering content in an admin theme. Only a newsletter sent to site admins (who have permission to view the admin theme) would match this use case.
So we should use the default theme instead or add an extra option to select the theme during generation of the insert content token.

B-Prod’s picture

If it can help, here is a base code that allows using templates from inside a custom module, dedicated to Mailchimp.

It is based on the use of a specific view mode for rendering the content.

So if we have a content type called my content type and a view mode called my view mode, you can use a custom template named node--my-content-type--my-view-mode.tpl.php in the templates folder of your custom theme.

To add a new view mode (even if it could be easily added by the custom module), you may use the Entity View Mode module.

/**
 * Implements hook_theme().
 */
function mymodule_theme($existing, $type, $theme, $path) {
  return [
    'node__my_content_type__my_view_mode' => [
      'render element' => 'content',
      'base hook' => 'node',
      'template' => 'node--my-content-type--my-view-mode',
      'path' => drupal_get_path('module', 'mymodule') . '/templates',
    ],
   );
}

/**
 * Implements hook_preprocess_node().
 */
function mymodule_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'my_view_mode') {
    $node = $variables['node'];

    $variables['theme_hook_suggestions'][] = 'node__' . $node->type . '__' . $variables['view_mode'];

    // Use absolute link.
    $uri = entity_uri('node', $node);
    $uri['options']['absolute'] = TRUE;
    $variables['node_url'] = url($uri['path'], $uri['options']);
  }
}
ruscoe’s picture

We're going to be ending support for the 7.x-3.x branch due to the upcoming deprecation of the v2.0 MailChimp API. If you're still interested in this feature, please feel free to reopen for the 7.x-4.x branch.

ruscoe’s picture

Status: Active » Closed (won't fix)
brunodbo’s picture

Version: 7.x-3.1 » 7.x-4.x-dev
Status: Closed (won't fix) » Active

Looking at how the HTML Mail module does this (as mentioned in #2), it's using https://www.drupal.org/project/echo to return the themed page as a string. If we want to use this approach, we could allow people to choose a theme when Echo is enabled, and render the entity in the selected theme.

Not sure if there are other ways to handle this today (e.g., set a specific theme for render() to use)?

brunodbo’s picture

Another approach entirely would be to add the 'Create campaign' form as a local task (tab) on the entity you want to send through MailChimp. Then the entity would get rendered in the theme that is being used (though I guess that could still be the admin theme depending on theme configuration).

(This would also change/improve the workflow for use cases where e.g., a newsletter is created in Drupal for sending through MailChimp: after creating the newsletter entity, the campaign form is only a tab away.)

samuel.mortenson’s picture

Status: Active » Closed (won't fix)

We’re in maintenance-mode for the Drupal 7 releases of Mailchimp, so only bug fixes can be committed going forward. Any new features should be developed for the Drupal 8 releases of Mailchimp. Thanks!

basvredeling’s picture

@samuel.mortenson shouldn't we just change the version to D8 then instead of closing this issue?

samuel.mortenson’s picture

Version: 7.x-4.x-dev » 8.x-1.x-dev
Status: Closed (won't fix) » Active

@basvredeling Sure, I can re-open this and change the version over.