Score:3

Is there a way to sync file naming across environments?

ph flag

I have 3 environments with version control. Dev, staging and production.

Now, say I create a new node in staging and create a corresponding file with the name: page--node--28.html.twig

On production environment users keep posting articles, so it will already have a node 28 which messes up the version control.

Is there any way to manage this seamlessly.

Score:4
ru flag

Do not use node ID based templates at all in such scenarios. Instead create your own custom theme suggestions based on a logic that does not change between environments:

function THEME_NAME_theme_suggestions_page_alter(array &$suggestions, array $variables) {

  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    $my_suggestion = $node->getSomethingThatWorksEverywhere();
    $suggestions[] = 'page__' . $my_suggestion;
  }
}
seventh_sniper avatar
ph flag
This is perfect, thank you. Also, while we are here, is there a way to migrate structural changes across environments like adding a new field in content type? Or should I ask this as a separate question?
ru flag
TL,DR: `drush config:export && git push` on dev and `git pull && drush config:import` on prod - google for "drupal configuration management" and you will find a lot on this topic
ru flag
Note: drush config:import will import/overwrite the complete site config, not incrementally add single configs
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.