简体   繁体   中英

Display a at runtime changeable property on each site

I want to display the name on every site of my grails app (this is not the app.name). Let's assume it is in the headline of the layout.

<h1>My app name</h1>

I would like to set this value at runtime and be able to edit it. My first idea was to store this value in a domain class. But then every controller action has to pass this domain object to the view.

So my questions are:

  • Is there a easy way to always access the value of a domain object?
  • Is there a better place to store the title of the application?

You can put things like this in a (singleton scoped) service and back it by domain object (eg key, value, locale) or by config (or both). Make the service listen into the livecycle events to load the values once on startup. Also provide a "setter", that writes down to the domain object for the next start. Then add your own tag to get easy access to the value(s). In the tag you can also add common things like rendering the value as markdown or fetch by current locale.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM