Is it possible to access a settings variable within a template?
Setting:
<#setting locale="${bean.locale}">
How can I use locale without reusing ${bean.locale} within the template to avoid duplicate code, especially if its a deeper hierarchy?
The locale is a Special Variable, and can be access like this : ${.locale}.
See the freemarker documentation
Related
I'm trying "mcamara/laravel-localization" package to localize my app and it works as expected except for one small issue, the package seems to override the config('app.locale') default value.
For instance if the default value of the locale property in config\app.php file is set to en end I changed the application language to french with the language switcher then config('app.locale') is evaluated to fr instead of the default en.
I hope the issue is clear so my question is: how can get the default locale as defined the config\app.php config file?
Thanks
whole point of that package is changing locale, no matter what the default locale is that package change it to whatever you config it to.
but you can get current locale anytime you want using currentLocale() method of App facade and change it with setLocale($yourLocale).
In order to get the current language code, write the following function:
app()->getLocale();
In order to activate the activation of a new language, you can write the following function:
app()->setLocale('fr');
To create a handler, it seems that I would need to create a template with a URI template to create bindings.
However, the bindings seem to me only possible as a path structure (e.g. /:id/:records/:department) instead of being searchParams (?id=1&department=IT)
How could I allow optional parameters in the URL for handlers?
You can access search params variables just as you would access it in the URL template. There's no need to strictly define all possible input parameters in the URL template.
You can use binds or parameters, or even a mix.
I have full code examples here.
Run the sql's...
Confirm your APIs have been created, and call the API...
In this case a
GET http://localhost:8080/ords/hr/parameters/headers-classic?id=4
What is the best way to add a new config setting in the configuration->Catalog->Search Engine Optimisations or any other such location in the core configuration.
I am developing an extension which will need to use this setting that I will define here.
Thanks
karam
If you are developing an extension, you can configure your field for administration using system.xml. The xpath will be catalog/groups/seo/fields/your_field (ref. Mage/Catalog/etc/system.xml).
To set a default for this value, you can either add the value to your module's config.xml using the xpath default/catalog/seo/your_field, or you can create an install script which will write the value to core_config_data.
How do I check a value from the request attribute in freemarker?
I tried <#if *${RequestParameters['servicesettings']} ??> but getting errors ->
Encountered "*" at line
Can anyone help?
It depends on the Web application framework, because FreeMarker itself doesn't expose the request parameters. (Well, except if the framework uses freemareker.ext.servlet.FreemarkerServlet which is kind of an extension to FreeMarker.) Also, usually you shouldn't access request parameters directly from an MVC template, or anything that is HTTP/Servlet specific.
As of the error message, what you have written has a few syntax errors... probably you meant <#if RequestParameters.servicesettings??> (it's not JSP - don't use ${...}-s inside FreeMarker tags). This will require that you have RequestParameters in the data-model, that I can't know for sure...
We should write like this:
${Request.requestattribute}
You can use
${requestParameters.servicesettings}.
According to the JavaDoc of the FreemarkerServlet:
It makes all request, request parameters, session, and servlet context attributes available to templates through Request, RequestParameters, Session, and Application variables.
The scope variables are also available via automatic scope discovery. That is, writing Application.attrName, Session.attrName, Request.attrName is not mandatory; it's enough to write attrName, and if no such variable was created in the template, it will search the variable in Request, and then in Session, and finally in Application.
You can simply write:
${attrName}
to get the value of a request attribute (that you might have set in a servlet request filter using request.setAttribute('attrName', 'value')
Worked for me with Freemarker 2.3.27-incubating
I'm probably not the first one facing this problem, but I couldn't find a proper answer anywhere.
I have a Windows Forms application that uses a strongly-typed DataSet. The designer uses a connection string defined in the application settings. The trouble is that this setting is defined as Application scope (thus read-only), and I need to be able to change it at runtime. In the settings designer, when the type of a setting is "Connection String", it's not possible to change the scope to "User". And the generated dataset doesn't provide a constructor allowing to choose the connection string at runtime, it always uses the one in the settings.
Do you know why MS introduced this restriction? Do you have any workaround?
I'm currently using a workaround that's really ugly: I change the type of the setting to "String", and the scope to "User". That way, I can change it at runtime and it works fine. The trouble is that when I need to modify the dataset in the designer, I have to change it back to "ConnectionString", otherwise the designer doesn't work.
Thanks in advance for your suggestions!
You can change the value of an ApplicationScope setting at runtime. While the generated and strong-typed property is readonly you can use:
Properties.Settings.Default["App1"] = "bbb";
After that, Properties.Settings.Default.App1 will read "bbb";
This should make it possible to leave the design time setting alone.
You cannot use Settings.Default.Save() for ApplicationScope settings but that is intentional. A normal User does not have the privileges to write in a subfolder of Program Files