can't you include in page component customheaderlibs?
you can use sling model to pass environment specific code to head.jsp
@Model(adaptables = Resource.class)
public class EnvironmentSpecificCodeModel {
@ValueMapValue
private String environmentSpecificCode;
@Inject
public EnvironmentSpecificCodeModel(Resource resource) {
// Fetch the environment-specific code here based on your needs
}
public String getEnvironmentSpecificCode() {
return environmentSpecificCode;
}
}
<%
// Use the Sling Model to fetch the environment-specific code
com.yourproject.core.models.EnvironmentSpecificCodeModel codeModel = resource.adaptTo(com.yourproject.core.models.EnvironmentSpecificCodeModel.class);
String environmentSpecificCode = codeModel.getEnvironmentSpecificCode();
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
<%=environmentSpecificCode%>
</script>
</head>
<body>
<!-- Your body content here -->
</body>
</html>