-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move the special $CONTENT_TITLE and $LAYOUT_TITLE values to context variables #172
Comments
Will this ever be implemented? |
Gave this yet another try today, and I remembered why I left this one alone for so long... In essence: a title can be anything. Developers aren't just putting text in between
The solution to handle all of the above was to put those "anything" parts in the correct places for the pattern given to This does mean that the resulting title parts are no longer under the control of the layout dialect, and so being able to assign the results to template-wide context variables is not possible with the current suite of processors, and adding a new processor to be able to handle this feels very out-of-place with the layout dialect. As such, I'm going to close this issue. For people coming to this in future and looking for ways to read the title, then some things that I thought of while attempting this:
<p th:include="~{::title}">The title will end up here</p>
class TitleModelProcessor extends AbstractAttributeModelProcessor {
@Override
protected void doProcess(ITemplateContext context, IModel model, AttributeName attributeName,
String attributeValue, IElementModelStructureHandler structureHandler) {
def titleText
model.accept(new AbstractModelVisitor() {
@Override
void visit(IText text) {
titleText = text
}
})
// Do whatever you want with the title now that you have it 🎉
println("Title is ${titleText}")
}
} As for being able to discern the content and layout title parts, that will depend on your own application as you'll know how those are put together. |
Reopening as I've had some inspiration on how to tackle this 💡 (Some 6 years later! 😅) |
These custom strings are only available within the scope of the
layout:title-pattern
processor, but there have been instances where devs have wanted access to these values elsewhere (usually the whole title).Would it be possible to convert these into variables that I add to the current processing context instead so they can be used elsewhere? In the process, removing the custom placeholder names and turning them to something accessible via an expression instead (eg:
${CONTENT_TITLE}
), taking advantage of the expression language to construct titles and any other strings using them.The text was updated successfully, but these errors were encountered: