Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public record RequestFeature(String context, String uri, Map<String, List<String
public RequestFeature(String uri, Map<String, List<String>> queryParameters) {
this(null, uri, queryParameters, null);
}

public boolean hasQueryParameter (String name) {
return queryParameters.containsKey(name);
}

public String getQueryParameter(String name, final String defaultValue) {
if (!queryParameters.containsKey(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.condation.cms.api.Constants;
import com.condation.cms.templates.DefaultTemplate;
import com.condation.cms.templates.Tag;
import com.condation.cms.templates.exceptions.TagException;
Expand Down Expand Up @@ -69,6 +70,9 @@ public void render(TagNode node, Renderer.Context context, Writer writer) {
var template = (DefaultTemplate) context.templateEngine().getTemplate(templateString);
if (template != null) {
CustomScopeStack scopeStack = new CustomScopeStack();

copyNamespaces(scopeStack, context);

template.evaluate(scopeStack, new NullWriter(), context.dynamicConfiguration());

var namespace = new HashMap<String, MacroTag.MacroFunction>();
Expand All @@ -89,6 +93,58 @@ public void render(TagNode node, Renderer.Context context, Writer writer) {
}
}

private void copyNamespaces(CustomScopeStack scopeStack, Renderer.Context context) {

var varNames = List.of(
Constants.TemplateNamespaces.CMS,
Constants.TemplateNamespaces.DEFAULT_MODULE_NAMESPACE,
Constants.TemplateNamespaces.NODE,
Constants.TemplateNamespaces.SITE,
"requestContext",
"theme",
"messages",
"PREVIEW_MODE",
"MANAGER",
"DEV_MODE",
"ENV",
"USERNAME"
);
varNames.forEach(name -> {
var value = context.scopes().getVariable(name);
if (value.isPresent()) {
scopeStack.setVariable(name, value.get());
}
});

if (context.scopes().getVariable(Constants.TemplateNamespaces.CMS).isPresent()) {
scopeStack.setVariable(
Constants.TemplateNamespaces.CMS,
context.scopes().getVariable(Constants.TemplateNamespaces.CMS).get()
);
}

if (context.scopes().getVariable(Constants.TemplateNamespaces.NODE).isPresent()) {
scopeStack.setVariable(
Constants.TemplateNamespaces.NODE,
context.scopes().getVariable(Constants.TemplateNamespaces.NODE).get()
);
}

if (context.scopes().getVariable(Constants.TemplateNamespaces.SITE).isPresent()) {
scopeStack.setVariable(
Constants.TemplateNamespaces.SITE,
context.scopes().getVariable(Constants.TemplateNamespaces.SITE).get()
);
}

if (context.scopes().getVariable(Constants.TemplateNamespaces.DEFAULT_MODULE_NAMESPACE).isPresent()) {
scopeStack.setVariable(
Constants.TemplateNamespaces.DEFAULT_MODULE_NAMESPACE,
context.scopes().getVariable(Constants.TemplateNamespaces.DEFAULT_MODULE_NAMESPACE).get()
);
}
}

private class CustomScopeStack extends ScopeStack {

private List<String> macros = new ArrayList<>();
Expand Down